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

Go to the previous, next section.

IdentDict--Dictionary Keyed by Object Address

SYNOPSIS

#include <nihcl/IdentDict.h>

BASE CLASS

Dictionary

DERIVED CLASSES

None

RELATED CLASSES

Assoc, Iterator, LookupKey

DESCRIPTION

An IdentDict (Identity Dictionary) is similar to a Dictionary, except that it uses isSame() for comparing key objects instead of isEqual(). Instances of class IdentDict are useful for "hash linking" additional information to an object. For example, the object I/O storeOn() function uses an IdentDict to record which objects within a complex data structure have already been stored, in order to be able to resolve multiple references to an object.

CONSTRUCTORS

IdentDict(unsigned capacity =DEFAULT_CAPACITY)
Constructs an empty IdentDict that can hold up to capacity associations (instances of classes derived from LookupKey). If an attempt is made to add more than capacity associations, reSize() is called to increase the IdentDict's capacity. Since this is an expensive operation, it is wise to supply a reasonable estimate for capacity.

SEARCHING

virtual LookupKey* assocAt(const Object& key) const
Returns a reference to the association in this IdentDict with the key object key. If key is not found, assocAt() returns 0.

virtual Object* atKey(const Object& key) const
Returns a pointer to the value object of the association in this IdentDict whose key object is the same as key. If key is not found, atKey() raises an NIHCL_KEYNOTFOUND exception.

virtual Object* atKey(const Object& key, Object& newValue)
Changes the value object of the association in this IdentDict with key key to newValue and returns a pointer to the old value object. If key is not found, atKey() raises an NIHCL_KEYNOTFOUND exception.

TESTING IDENTDICTS

virtual bool includesKey(const Object& key) const
Returns YES if there is an association in this IdentDict with the key object key.

PROTECTED MEMBERS

Hashing and Searching

virtual int findIndexOf(const Object& lkey) const
Searches this IdentDict for a key object that is the same (i.e. isSame()) as the key object of the LookupKey lkey and returns the index of this object, if found, or the index of an empty slot in the hash table where lkey should be inserted.

virtual unsigned hashOf(const Object& lkey) const
Computes a number suitable for use as a hash table probe by returning the address of the key object of the LookupKey lkey.

EXCEPTIONS RAISED

None

Go to the previous, next section.