#include <CNCL/HashList.h>
CN_HASHLIST
CNHashTable
None
CNHashDynamic, CNKey, CNKeyString, CNKeyInt
CHHashIterator does NOT work for CNHashList
CNHashList
is a class which provides a hash table with
unrestricted capacity. Contrary to CNHashStatic the keys occuring more
than once are stored in lists, i.e. the capacity of the hash table does
not restrict the number of keys, that may be stored. Nontheless the
capacity should be large enough for the number of keys to be stored in.
Constructors:
CNHashList(unsigned long cap = DEFAULT_HASH_TABLE_CAPACITY);
CNHashList(CNParam *param);
CNHashList
. The hash table's capacity is set to
the value passed to CNHashList. The capacity is static. Nontheless,
you can store more keys since they are stored in lists.
Destructors:
~CNHashList();
CNHashList
provides the member functions required by CNCL and
CNHashTable
.
Some member functions defined in CNHashTable
and
implemented in CNHashList
demand further explanation:
void store_key(CNKey *k);
get_key()
and
get_object()
should detect it. If a hashvalue occures the second
time it will be stored in a list. Therefore the hash table will never be
full unless the memory is exhausted.
bool delete_key(CNKey *k);
FALSE
is returned, otherwise TRUE
.
bool delete_key_absolutely(CNKey *k);
FALSE
is returned, otherwise TRUE
.
The following example shows how to use a CNHashList
object in
order to store and retrieve CNCL compatible objects.
CNHashList tab(200); CNKeyString ks("Test", NIL); CNObject *obj = &ks; tab.store_key(new CNKeyString("Jabba", obj)); tab.store_key(new CNKeyString("Dabba")); tab.store_key(new CNKeyString("Dooo")); if (tab.get_object(CNKeyString("Jabba")) != obj) cout << "strange behaviour\n"; else cout << "found obj\n"; tab.store_key(new CNKeyInt(10, obj)); // error, key of different type tab.reset_absolutely(); tab.store_key(new CNKeyInt(10, new CNObject)); // okay // free memory of all keys and their objects tab.reset_absolutely_w_obj();
Go to the first, previous, next, last section, table of contents.