Go to the first, previous, next, last section, table of contents.


CNHashDynamic -- Hash Tables with Dynamic Capacity

SYNOPSIS

#include <CNCL/HashDynamic.h>

TYPE

CN_HASHDYNAMIC

BASE CLASSES

CNHashTable

DERIVED CLASSES

None

RELATED CLASSES

CNHashStatic, CNHashIterator, CNKey, CNKeyString, CNKeyInt, CNManager

DESCRIPTION

CNHashDynamic is a class which provides a hash table with dynamic capacity for storing and retrieving CNCL compatible objects. Constructors:

CNHashDynamic(unsigned long cap = DEFAULT_HASH_TABLE_CAPACITY);
CNHashDynamic(CNParam *param);
Initializes CNHashDynamic. The hash table's capacity is set to the value passed to HashDynamic. The capacity is dynamic, i.e. if the number of entries exceeds 3/4 of the hash table's capacity, it is enlarged to a proper value.

Destructors:

~CNHashDynamic();
Frees all internally allocated resources.

CNHashDynamic provides the member functions required by CNCL and CNHashTable. Some member functions defined in CNHashTable and implemented in CNHashDynamic demand further explanation:

void store_key(CNKey *k);
Stores a key into the homogenous hash table. Therefore, only keys of the same type may be stored into the same table. If you nevertheless try to store keys of different types into one table, it might be detected by the methods get_key() and get_object(). The capacity is dynamic, i.e. if the number of entries exceeds 3/4 of the hash table's capacity, it is enlarged to a proper value.
bool delete_key(CNKey *k);
Deletes the key from the actual hash table which matches the given key. After having deleted a key from the hash table, the whole table is rehashed, i.e. the positions of all entries within the hash table are recalculated and all entries are stored in a new hash table. This might lead to small time delays when handling large hash tables. This method does not free the memory allocated for the keys stored in the hash table. If the supplied key does not match any in the table, FALSE is returned, otherwise TRUE.
bool delete_key_absolutely(CNKey *k);
Deletes the key from the actual hash table, which matches the given key. After having deleted a key from the hash table, the whole table is rehashed. This method does free the memory allocated for the keys stored in the hash table. If the supplied key does not match any in the table, FALSE is returned, otherwise TRUE.

Refer to CNHashStatic for an example as to how to use a CNHashDynamic object in order to store and retrieve CNCL compatible objects.


Go to the first, previous, next, last section, table of contents.