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


CNHashTable -- Abstract Base Class for Hash Tables

SYNOPSIS

#include <CNCL/HashTable.h>

TYPE

CN_HASHTABLE

BASE CLASSES

CNObject

DERIVED CLASSES

CNHashStatic, CNHashDynamic

RELATED CLASSES

CNKey, CNKeyString, CNKeyInt, CNHashIterator, CNManager

DESCRIPTION

CNHashTable is an abstract base class for storing and retrieving CNCL compatible objects. Constructors:

CNHashTable();
CNHashTable(CNParam *param);
Initializes CNHashTable.

CNHashTable defines the following structs and constants:

const unsigned long DEFAULT_HASH_TABLE_CAPACITY = 101;
The default capacity of a hash table. This value is used in derived classes.
struct HashEntry { CNKey *he_CNKey; unsigned long he_HashValue; };
Defines a single entry of the hash table.

CNHashTable provides the following virtual functions which have to be defined in derived classes:

virtual void store_key(CNKey *k) = 0;
virtual void store_key(CNKey &k) = 0;
Stores a key into the actual hash table (derived from class HashTable). The actual hash table is a homogenous table. Therefore, only keys of the same type may be stored into one table. If you nevertheless try to store keys of a different type into one table, it might be detected by the methods get_key() and get_object(). Refer to the description of the derived classes for further information.
virtual CNKey *get_key(CNKey *k) const = 0;
virtual CNKey *get_key(CNKey &k) const = 0;
Returns the key which matches the supplied key. If no matching key was found, NIL is returned.
virtual CNObject *get_object(CNKey *k) const = 0;
virtual CNObject *get_object(CNKey &k) const = 0;
Returns the object of the key which matches the supplied key. If no matching key was found or if no object has been stored in the key, NIL is returned.
virtual bool reset() = 0;
Deletes all entries of the actual hash table and resets it to its initial state. This method does not free the memory allocated for the keys stored in the hash table or the objects stored in the keys. If the hash table is already empty, FALSE is returned, otherwise TRUE.
virtual bool reset_absolutely() = 0;
Deletes all entries of the actual hash table and resets it to its initial state. This method frees the memory allocated for the keys stored in the hash table, but does not free memory allocated for objects stored in keys. If the hash table is already empty, FALSE is returned, otherwise TRUE.
virtual bool reset_absolutely_w_obj() = 0;
Deletes all entries of the actual hash table and resets it to its initial state. This method frees the memory allocated for the keys stored in the hash table and frees the memory for the objects contained in the keys. If the hash table is already empty, FALSE is returned, otherwise TRUE.
virtual bool delete_key(Key *k) = 0;
virtual bool delete_key(CNKey &k);
Deletes the key k from the actual hash table. This method neither frees the memory allocated for the key stored in the hash table nor for the object stored in the key. If the supplied key does not match any in the table, FALSE is returned, otherwise TRUE.
virtual bool delete_key_absolutely(CNKey *k) = 0;
virtual bool delete_key_absolutely(CNKey &k) = 0;
Deletes the key k from the actual hash table. This method frees the memory allocated for the key stored in the hash table, but does not free the memory allocated for the object stored in the key. If the supplied key does not match any in the table, FALSE is returned, otherwise TRUE.
virtual bool delete_key_absolutely_w_obj(CNKey *k) = 0;
virtual bool delete_key_absolutely_w_obj(CNKey &k) = 0;
Deletes the key k from the actual hash table. This method frees the memory allocated for the key stored in the hash table and frees the memory allocated for the object stored in the key. If the supplied key does not match any in the table, FALSE is returned, otherwise TRUE.
virtual bool is_full() const = 0;
If the actual table's capacity is exhausted, TRUE is returned, otherwise FALSE.
virtual bool is_empty() const = 0;
If the actual table is empty, TRUE is returned, otherwise FALSE.
virtual unsigned long get_num_entries() const = 0;
Returns the number of entries of the actual table.
virtual unsigned long get_capacity() const = 0;
Returns the capacity of the current table.


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