Return to Index

LinearHash

A templated string-key hash table collection class. The hash table is implemented with linear collision resolution, and can be traversed using the first(..) / next(..) methods. The hash can only store pointers to objects. Therefore, the declaration
   LinearHash‹ SomeClass › my_hash;
declares a string hash of pointers of type SomeClass. To traverse the elements in the table:
   String key = "";
   SomeClass *ptr = my_hash.first( key );
   while (ptr) {
     ...
     ptr = my_hash.next( key );
   }


Method Summary:
LinearHash::LinearHash();
void LinearHash::setAutoDelete(bool b);
void LinearHash::clear();
int LinearHash::length();
int LinearHash::itemCount();
void LinearHash::grow();
void LinearHash::insert(const String& key, type* data);
type* LinearHash::remove(const String& key);
type* LinearHash::lookup(const String& key);
type* LinearHash::first(String& key);
type* LinearHash::next(String& key);



LinearHash::LinearHash
LinearHash::LinearHash();

Construct a new linear string key hash table.

void LinearHash::setAutoDelete
void LinearHash::setAutoDelete(bool b);

or when the the hash itself is deleted.
Parameters:
bool bEnable or disable auto-deletion.

void LinearHash::clear
void LinearHash::clear();

Empties the hash of all objects, deleting them if auto-deletion is enabled.

int LinearHash::length
int LinearHash::length();

Returns the number of items in the hash.

int LinearHash::itemCount
int LinearHash::itemCount();

Returns the number of items in the hash.

void LinearHash::grow
void LinearHash::grow();

Increases the table size of the hash. Note that this involves rehashing all the elements. The table is automatically grown when the load factor passes a threshold.

void LinearHash::insert
void LinearHash::insert(const String& key, type* data);

Insert a key-data pair into the table.
Parameters:
const String& keyThe identifier key.
type* dataA pointer to the object identified by the key.

type* LinearHash::remove
type* LinearHash::remove(const String& key);

Remove a key-data pair from the table.

Returns: If auto-deletion is off, a pointer to the object is returned.
Parameters:
const String& keyThe identifier key.

type* LinearHash::lookup
type* LinearHash::lookup(const String& key);

Search the table for a key-data pair.

Returns: A pointer to the object is returned if is found, otherwise NULL.
Parameters:
const String& keyThe identifier key.

type* LinearHash::first
type* LinearHash::first(String& key);

Returns the first object in the table along with its key. Note that there is no rule imposed on what order objects are returned
Parameters:
String& keyThis will be assigned the key of the object returned.

type* LinearHash::next
type* LinearHash::next(String& key);

Returns the next object in the table along with its key. Note that there is no rule imposed on what order objects are returned
Parameters:
String& keyThis will be assigned the key of the object returned.


Generated automatically by docgen 0.0.1
© 2003 Aron Dobos