Return to Index
PtrHash
A templated pointer-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
   PtrHash SomeClass my_hash;
declares a pointer-key hash of pointers of type SomeClass. To traverse the
elements in the table:
   Ptr key = NULL;
   SomeClass *ptr = my_hash.first( key );
   while (ptr) {
     ...
     ptr = my_hash.next( key );
   }
PtrHash::PtrHash |
PtrHash::PtrHash(int size);
Construct a new pointer key hash table of a specified table size. |
Parameters: |
int | size | The size of the table. Note that collisions are resolved with chaining. |
|
void PtrHash::setAutoDelete |
void PtrHash::setAutoDelete(bool b);
or when the the hash itself is deleted. |
Parameters: |
bool | b | Enable or disable auto-deletion. |
|
void PtrHash::clear |
void PtrHash::clear();
Empties the hash of all objects, deleting them if auto-deletion is enabled. |
int PtrHash::length |
int PtrHash::length();
Returns the number of items in the hash. |
int PtrHash::itemCount |
int PtrHash::itemCount();
Returns the number of items in the hash. |
void PtrHash::resize |
void PtrHash::resize(int new_size);
Resizes the hash table to the specified size. Note that this involves rehashing all the elements. |
Parameters: |
int | new_size | The new size of the table. |
|
void PtrHash::insert |
void PtrHash::insert(CPtr key, type* data);
Insert a key-data pair into the table. |
Parameters: |
CPtr | key | The identifier key. |
type* | data | A pointer to the object identified by the key. |
|
type* PtrHash::remove |
type* PtrHash::remove(CPtr key);
Remove a key-data pair from the table.
Returns: If auto-deletion is off, a pointer to the object is returned. |
Parameters: |
CPtr | key | The identifier key. |
|
type* PtrHash::lookup |
type* PtrHash::lookup(CPtr key);
Search the table for a key-data pair.
Returns: A pointer to the object is returned if is found, otherwise NULL. |
Parameters: |
CPtr | key | The identifier key. |
|
type* PtrHash::first |
type* PtrHash::first(Ptr& 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: |
Ptr& | key | This will be assigned the key of the object returned. |
|
type* PtrHash::next |
type* PtrHash::next(Ptr& 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: |
Ptr& | key | This will be assigned the key of the object returned. |
|
Generated automatically by docgen 0.0.1
© 2003 Aron Dobos