Hash Table templateA hash table is a list of buckets. More...
#include <thashtable.h>
Public Types | |
typedef uint32(* | THashFunc )(const T &, uint32) |
Hash function type. | |
Public Member Functions | |
THashTable (THashFunc, int32=10) | |
Constructor with hash function. | |
THashTable (const THashTable< T > &) | |
Copy constructor. | |
THashTable (THashFunc, const TContainer< T > &) | |
Constructor with container. | |
~THashTable () | |
Destructor. | |
THashTable< T > & | operator= (const THashTable< T > &) |
Assignment operator, uses copy. | |
void | setHashFunction (THashFunc) |
Set hash function. | |
bool | resize (int32) |
Resize the table, set number of hash buckets. | |
virtual TContainer< T > * | newInstance () const |
virtual int32 | total () const |
virtual bool | isEmpty () const |
virtual bool | add (const T &item) |
virtual bool | remove (const T &item) |
virtual bool | remove (const TIterator< T > &iter) |
virtual bool | removeAt (int32 index) |
virtual void | removeAll () |
virtual T & | lookup (const T &item) const |
virtual bool | contains (const T &item) const |
virtual int32 | occurrences (const T &item) const |
virtual TIterator< T > * | newIterator () const |
Hash Table template
A hash table is a list of buckets.
It assigns values to items (template) using a hash function and puts them into the bucket, which table index equals the item's calculated value.
typedef uint32(* THashFunc)(const T &, uint32) |
Hash function type.
Reimplemented in TBag< T >, THashDictionary< TKey, TObject >, and THashSet< T >.
THashTable | ( | THashFunc | func, | |
int32 | size = 10 | |||
) | [inline] |
Constructor with hash function.
[in] | func | Hash function the table uses. |
[in] | size | Size (number of buckets) of new table. |
THashTable | ( | const THashTable< T > & | table | ) | [inline] |
Copy constructor.
[in] | table | Hash table to copy. |
THashTable | ( | THashFunc | func, | |
const TContainer< T > & | cont | |||
) | [inline] |
Constructor with container.
[in] | func | Hash function the table uses. |
[in] | cont | Container to construct the table from. |
~THashTable | ( | ) | [inline] |
Destructor.
THashTable< T > & operator= | ( | const THashTable< T > & | table | ) | [inline] |
Assignment operator, uses copy.
[in] | table | Assign left side (this) to table. |
void setHashFunction | ( | THashFunc | func | ) | [inline] |
Set hash function.
[in] | func | New hash function. |
bool resize | ( | int32 | newsize | ) | [inline] |
Resize the table, set number of hash buckets.
[in] | newsize | New number of hash buckets. |
TContainer< T > * newInstance | ( | ) | const [inline, virtual] |
int32 total | ( | ) | const [inline, virtual] |
Return number of items.
Reimplemented from TContainer< T >.
bool isEmpty | ( | ) | const [inline, virtual] |
Is container empty?
Reimplemented from TContainer< T >.
bool add | ( | const T & | rObj | ) | [inline, virtual] |
Add item to container.
[in] | rObj | Item to add. |
Implements TContainer< T >.
Reimplemented in TBag< T >, and THashSet< T >.
bool remove | ( | const T & | rObj | ) | [inline, virtual] |
Remove equal item.
[in] | rObj | Item to remove. |
Implements TContainer< T >.
Reimplemented in TBag< T >.
bool remove | ( | const TIterator< T > & | iter | ) | [inline, virtual] |
Remove item at current iterator position.
[in] | iter | Points to item to remove. |
Implements TContainer< T >.
bool removeAt | ( | int32 | idx | ) | [inline, virtual] |
Remove item at given index.
[in] | idx | Index of item to remove. |
Implements TContainer< T >.
void removeAll | ( | ) | [inline, virtual] |
T & lookup | ( | const T & | rObj | ) | const [inline, virtual] |
Searches for the item equal to the specified item in the list and returns the first occurrence.
[in] | rObj | Item to look up. |
Reimplemented from TContainer< T >.
bool contains | ( | const T & | rObj | ) | const [inline, virtual] |
See if container has equal item.
[in] | rObj | Item to compare. |
Reimplemented from TContainer< T >.
int32 occurrences | ( | const T & | rObj | ) | const [inline, virtual] |
Count occurrences of equal items.
[in] | rObj | Item to compare. |
Reimplemented from TContainer< T >.
TIterator< T > * newIterator | ( | ) | const [inline, virtual] |