#include <AbstractHashTable.h>
Public Types | |
| typedef size_t | size_type |
| The type of the hash indeces. | |
| typedef ListItem< T *> * | hash_element |
| The type of a list of hash elements. | |
Public Methods | |
| AbstractHashTable (const char *nameBuff="Unnamed") | |
| Constructor. | |
| AbstractHashTable (size_type initial_size, const char *nameBuff="Unnamed") | |
| Constructor. | |
| virtual | ~AbstractHashTable () |
| Dummy destructor. | |
| bool | empty () const |
Returns true if the list is empty and false otherwise. | |
| operator bool () const | |
Returns true if the list is empty and false otherwise. | |
| int | size () const |
| Returns the number of elements in the hash table. | |
| virtual T * | find (KEY &key) const |
| Return the item in the hash table with the given key. More... | |
| virtual T * | first () const |
| Return the ``first'' element in the hash table. | |
| virtual void | add (KEY &key) |
| Add a key to the hash table. | |
| virtual void | add (KEY &key, T *&item) |
| Add a key to the hash table and return the hash table item that contains it. | |
| virtual void | remove (KEY &key, bool &status) |
| Remove a hash table item with the given key. More... | |
| virtual void | remove (T *&item, bool &status) |
| Remove a hash table item. More... | |
| virtual void | remove (T *&item, KEY &key, bool &status) |
| Remove a hash table item and return the item's key. More... | |
| virtual T * | next (T *item) |
| Returns the next element in the hash table's list of hash elements. | |
| int | write (ostream &os) const |
| Write the hash table to an output stream. | |
| int | read (istream &is) |
| Read a hash table from an input stream. | |
| void | clear () |
| Empty the hash table. | |
| void | statistics (ostream &os) |
| TODO. | |
| bool & | ignore_duplicates () |
| A flag that can be set to ignore duplicates in the hash table. | |
| void | set_hash_fn (size_type(*hashfn)(const KEY &, size_type)) |
| Set the hash function used by this HT. | |
Public Attributes | |
| bool | using_prime_ht |
| If true, then the hash table size is prime. Can be set by the user. | |
| size_type(* | curr_hashfn )(const KEY &, size_type) |
| A pointer to the current hash function. | |
Protected Methods | |
| virtual size_type | hash (KEY &key, size_type table_size) const |
| Hashes a key with the given table size. | |
| virtual T * | insert (KEY *key) |
| Add a key to the tree. | |
| void | insert (T *item, const bool resize_OK=true) |
| Add a hash table item to the tree. | |
| virtual void | extract (T *item, bool &status) |
| Remove a hash table item. More... | |
| void | resize (const int newsize=-1) |
| TODO. | |
Protected Attributes | |
| LinkedList< T *> | data |
| pointers to actual data values. | |
| BasicArray< ListItem< T *> *> | table |
| The hash table, which points at list item elements. | |
| BasicArray< int > | bucket_size |
| The size of the bucket in the hash table;. | |
| double | max_load |
| Resize the table if (# vals)/(table.size()) > max_load. | |
| bool | ignore_duplicates_flag |
| Ignore duplicates that are hashed if true. | |
Note: the 'next' method doesn't work if ignore_duplicate==false and there exist duplicates in the hash table. The could probably be fixed by using a iterator construct, though, instead of this method. Consequently, ignore_duplicate==true by default.
|
||||||||||||||||
|
Remove a hash table item.
The status flag is |
|
||||||||||
|
Return the item in the hash table with the given key. Returns null if the table is empty or if the item is not in the tree. |
|
||||||||||||||||||||
|
Remove a hash table item and return the item's key.
The status flag is |
|
||||||||||||||||
|
Remove a hash table item.
The status flag is |
|
||||||||||||||||
|
Remove a hash table item with the given key.
The status flag is |