golib  0.5
goHashTable< I, O > Class Template Reference

#include <gohashtable.h>

Public Member Functions

 goHashTable (goUInt32 mod_value=511)
 
virtual ~goHashTable ()
 
void setModValue (goUInt32)
 
void setDefault (const O &d)
 Set the default return value. More...
 
void clear ()
 
goUInt32 getModValue () const
 
O & operator[] (const I &in)
 
virtual void add (const I &key, const O &value)
 
virtual O remove (const I &key)
 
bool fail ()
 
goArray< void * > & getLists ()
 

Protected Member Functions

void addEntry (goUInt32 table, void *entry)
 
void eraseLists ()
 Erases all lists and resizes the table to zero.
 

Protected Attributes

bool lastFailed
 
goUInt32 modValue
 
goArray< void * > theTable
 
dummy
 

Detailed Description

template<class I, class O>
class goHashTable< I, O >

Implementation of a simple hash table. You always have to check fail() before doing anything to the result of an operator[] call, if you don't, the code is likely to crash. If you do, it should be safe. The table index is calculated out of the last lb(modValue+1) bits of the key.

Author
Christian Gosch
Note
This class is considered as not tested hard enough. If you find bugs, please contact the author.
I didn't say this is fast, did I?
Todo:
I need testing!!! Class was changed together with goList 21.8.2001. Optimizations are possible.

Constructor & Destructor Documentation

◆ ~goHashTable()

template<class I , class O >
goHashTable< I, O >::~goHashTable ( )
virtual
Todo:
Problem: Hashtable für Zeiger. Daten müssen per Hand gelöscht werden.

Member Function Documentation

◆ remove()

template<class I, class O >
O goHashTable< I, O >::remove ( const I &  key)
virtual
Note
Only superficially tested.
Returns
The value for the given key.

◆ setDefault()

template<class I , class O>
void goHashTable< I, O >::setDefault ( const O &  d)

Set the default return value.


This value is returned whenever operator[] fails, i.e. there is no output value stored for a given input value.

@param d Default value.

◆ setModValue()

template<class I , class O >
void goHashTable< I, O >::setModValue ( goUInt32  i)

Sets the hash mod value. Only call this once, before you do anything else with the hash table object. If you don't, or if you call it more than once, unexpected behaviour is the result. should always be something like (2^n-1).

Attention
All previous entries are lost when calling this method. Call only once!
Parameters
iMod value.

The documentation for this class was generated from the following files: