Return to Index

StrHash

A templated string-key hash table collection class. The hash table is implemented with a chaining algorithm, and can be traversed using the first(..) / next(..) methods. The hash can only store pointers to objects. Therefore, the declaration
   StrHash‹ 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:
StrHash::StrHash(int size);
void StrHash::setAutoDelete(bool b);
void StrHash::clear();
int StrHash::length();
int StrHash::itemCount();
void StrHash::resize(int new_size);
void StrHash::insert(const String& key, type* data);
type* StrHash::remove(const String& key);
type* StrHash::lookup(const String& key);
type* StrHash::first(String& key);
type* StrHash::next(String& key);



StrHash::StrHash
StrHash::StrHash(int size);

Construct a new string key hash table of a specified table size.
Parameters:
int sizeThe size of the table. Note that collisions are resolved with chaining.

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

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

void StrHash::clear
void StrHash::clear();

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

int StrHash::length
int StrHash::length();

Returns the number of items in the hash.

int StrHash::itemCount
int StrHash::itemCount();

Returns the number of items in the hash.

void StrHash::resize
void StrHash::resize(int new_size);

Resizes the hash table to the specified size. Note that this involves rehashing all the elements.
Parameters:
int new_sizeThe new size of the table.

void StrHash::insert
void StrHash::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* StrHash::remove
type* StrHash::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* StrHash::lookup
type* StrHash::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* StrHash::first
type* StrHash::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* StrHash::next
type* StrHash::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