WWC snapshot of http://www.alw.nih.gov/Docs/NIHCL/nihcl_45.html taken on Sat Jun 10 19:14:01 1995

Go to the previous, next section.

SortedCltn--Sorted Collection

SYNOPSIS

#include <nihcl/SortedCltn.h>

BASE CLASS

OrderedCltn

DERIVED CLASSES

KeySortCltn

RELATED CLASSES

Iterator, Range

DESCRIPTION

A SortedCltn is similar to an OrderedCltn, except that the objects in the SortedCltn are kept in ascending order, as determined by their virtual function compare(), rather than by the sequence in which the objects are added.

CONSTRUCTORS

SortedCltn(unsigned capacity =DEFAULT_CAPACITY)
Constructs an empty SortedCltn that can hold up to capacity objects. An
NIHCL_ALLOCSIZE error is raised if capacity is not greater than 0. If an attempt is made to add more than capacity objects to a SortedCltn, reSize() is called to increase its capacity.

ADDING OBJECTS

virtual Object* add(Object& ob)
Adds the object ob to this SortedCltn and returns a pointer to ob. A SortedCltn applies the virtual function compare() to determine where the object is inserted. Objects that compare() the same are kept in the sequence in which they were added.

REMOVING OBJECTS

Object* remove(const Object& ob)
Removes the first object in this SortedCltn that compare()s equal to ob, and returns a pointer to it. Returns nil if no equal object is found.

SEARCHING

int findIndexOf(const Object& key) const
Performs a binary search on this SortedCltn and returns an index to a pointer to an object which compare()s equal to the argument key. However, this is not necessarily the index of the first object pointer of a sequence of equal objects. Returns -1 if key is less than all other objects in this SortedCltn, or if this SortedCltn is empty. If no object in this SortedCltn is equal to key, returns the greatest pointer index of an object that is less than key.

virtual unsigned occurrencesOf(const Object& ob) const
Returns the number of objects in this SortedCltn that compare() equal to ob.

Range findRangeOf(const Object& key) const
Returns the range of indices of the objects that compare() equal to key. If no equal objects are found, returns a zero-length Range whose firstIndex() is the index at which key would be inserted in this SortedCltn.

PROTECTED MEMBERS

Searching

int findIndexOfFirstKey(int i) const
int findIndexOfLastKey(int i) const
Finds the index of the first (or last) object in the sequence of objects that compare() equal to the object at index i.

DISABLED MEMBER FUNCTIONS

virtual Object* addAfter(const Object& ob, Object& newob)
virtual Object* addAllLast(const OrderedCltn&)
virtual Object* addBefore(const Object& ob, Object& newob)
virtual Object* addLast(Object& ob)
virtual void atAllPut(Object& ob)
virtual int indexOfSubCollection(const SeqCltn& cltn, int start =0) const
virtual void replaceFrom(int start, int stop, const SeqCltn& replacement, int startAt =0)
virtual void sort()
These functions are implemented as shouldNotImplement().

EXCEPTIONS RAISED

None

Go to the previous, next section.