WWC snapshot of http://www.alw.nih.gov/Docs/NIHCL/nihcl_20.html taken on Sat Jun 10 19:13:44 1995

Go to the previous, next section.

KeySortCltn--Keyed Sorted Collection

SYNOPSIS

#include <nihcl/KeySortCltn.h>

BASE CLASS

SortedCltn

DERIVED CLASSES

None

RELATED CLASSES

Assoc, Iterator, LookupKey

DESCRIPTION

A KeySortCltn is a SortedCltn that allows the sorting of value objects by means of separate key objects. Each element of the collection is actually a key/value pair, but the sorting of the elements within the collection is based upon the key values alone.

CONSTRUCTORS

KeySortCltn(int capacity =DEFAULT_CAPACITY)
Constructs an empty KeySortCltn 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 KeySortCltn, reSize() is called to increase its capacity.

ADDING OBJECTS

virtual Assoc* addAssoc(Object& key, Object& value)
Constructs an association (an instance of class Assoc) with the specified key and value objects, inserts it into this KeySortCltn in ascending order sorted on the key object, and returns a pointer to the newly constructed association. The caller is responsible for deleting this association when no longer needed.

virtual Collection& addValuesTo(Collection& cltn) const
virtual Collection& addKeysTo(Collection& cltn) const
Adds the value or key objects in this KeySortCltn in sorted order to the Collection cltn, and returns a reference to cltn.

virtual Collection& addContentsBeforeTo(Object& key, Collection& cltn)
Adds all the associations in this KeySortCltn whose key objects are less than or equal to key to the Collection cltn, and returns a reference to cltn.

SEARCHING

virtual Object* atKey(Object& key)
Returns the value object associated with the argument key. Returns nil if key is not found.

INDEXING KEYSORTCLTNS

virtual LookupKey* assocAt(int i)
Returns a pointer to the ith association in this KeySortCltn.

virtual Object* keyAt(int i)
virtual Object* valueAt(int i)
Returns a pointer to the key or value object of the ith association in this KeySortCltn.

EXCEPTIONS RAISED

None

Go to the previous, next section.