Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::SortedList< T, comparator > Class Template Reference

#include <SortedList.h>

Inheritance diagram for util::SortedList< T, comparator >:

util::List< T > util::Iterator< T > util::Object List of all members.

Detailed Description

template<class T, class comparator = std::greater<T>>
class util::SortedList< T, comparator >

SortedList is a sorted list of any objects (including primitive data types).

The items added to the list will always maintain ascending sort order by default. The order may be changed using the second template parameter. The objects added to the list must have well-defined copy behavior plus the operators > (or <) and == defined. They must also provide a default (empty) constructor. Primitive types can be used as such with no special actions. The implementation guarantees O(log(N)) complexity for searches. The complexity for insertions is at worst O(log(N) + N).

Template parameters:


Public Methods

 SortedList (int initialSlots=16, int blockSize=16)
 Constructs a new sorted list with the given initial capacity and block size.

void addElement (const T &element)
 Adds an element to the list.

int indexOf (const T &element) const
 Get the index of the first occurrence of the given element.

void setMaximumSize (int size)
 Restrict the maximum size of this list to size.

int getMaximumSize (void)
 Get the maximum size of the list.


Constructor & Destructor Documentation

template<class T, class comparator>
util::SortedList< T, comparator >::SortedList int    initialSlots = 16,
int    blockSize = 16
 

Constructs a new sorted list with the given initial capacity and block size.

Parameters:
initialSlots  the number of items that can the list can initially hold without expanding
blockSize  the number of slots the list will expand each time its capacity is exceeded


Member Function Documentation

template<class T, class comparator>
void util::SortedList< T, comparator >::addElement const T &    element [virtual]
 

Adds an element to the list.

The added element must be of some elementary type or define the operators >, >= and ==. It must also provide a default (parameterless) constructor.

Parameters:
T  the element to be added

Reimplemented from util::List< T >.

template<class T, class comparator>
void util::SortedList< T, comparator >::setMaximumSize int    size
 

Restrict the maximum size of this list to size.

If the size of the list exceeds this value, the last element will be discarded.

Parameters:
size  the maximum size, initialized to MAXINT


The documentation for this class was generated from the following file:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.