#include <hash.h>
Inheritance diagram for Hash_table< Key, Value, Hash_func, Compare_func >:


Public Types | |
| typedef Hash_iterator< Key, Value > | Iterator |
Public Member Functions | |
| Hash_table (bool physical=false, Size init_buckets=0, bool alloc_nodes=false) | |
| void | init (bool physical=false, Size init_buckets=0, bool alloc_nodes=false) |
| void | clear () |
| void | free_and_clear () |
| bool | has_key (Key key) |
| Value * | get (Key key) |
| void | insert (Hash_node< Key, Value > &node) |
| bool | remove (Key key) |
| bool | grow () |
| Iterator | begin () |
| Iterator | end () |
| void | print () |
| void | unit_test () |
Public Attributes | |
| Array< List< Hash_node< Key, Value > > > | buckets |
Protected Member Functions | |
| unsigned | get_bucket_index (Key key) |
| List_iterator< Hash_node< Key, Value > > | find (unsigned bucket_index, Key key) |
Protected Attributes | |
| Hash_func | hash_func |
| Compare_func | compare_func |
| bool | physical_memory |
| bool | alloc_nodes |
| bool | physical |
Static Protected Attributes | |
| const Size | MAX_KEY_SIZE = 1024 |
|
|||||
|
|
|
||||||||||||||||||||
|
Call init() with the given arguments.
|
|
|||||||||
|
Return a hash iterator pointing at the first element of the hash.
|
|
|||||||||
|
Clear the hash table and free its memory.
|
|
|||||||||
|
Return a hash iterator indicating the end of the hash (after the last element).
|
|
||||||||||||||||
|
Attempt to find the given key in the hash, and if it's found, return an iterator pointing at its bucket position.
|
|
|||||||||
|
Free each node in the hash, and then clear the hash. This function assumes that the hash nodes were initially allocated from virtual memory and that nothing else is going to free them. |
|
||||||||||
|
Return the value that corresponds to the given key.
|
|
||||||||||
|
Return the bucket index corresponding to the given key.
|
|
|||||||||
|
|
|
||||||||||
|
Return true if the hash table contains the given key, and false otherwise.
|
|
||||||||||||||||||||
|
Allocate memory for the hash table's buckets. Set physical to true if the bucket data should be allocated from physical memory. Otherwise leave physical false and data will be allocated from persistent virtual memory. init_buckets is the initial number of buckets to create. The hash table is currently not growable, so choose init_buckets wisely. If alloc_nodes is true, then the hash table is responsible for managing the memory for the actual hash nodes within each bucket. This includes both allocating memory for the nodes and deallocating them upon removal. |
|
||||||||||
|
Insert a key/value pair into the hash table. If the key/value pair is already present, then it will be replaced with the new value. |
|
|||||||||
|
Print a hash table as its address and all of its key/value pairs.
|
|
||||||||||
|
Remove the given key from the hash table. Return true on success, or false if the given key could not be found. |
|
|||||||||
|
Perform some basic tests to make sure this works as it should.
|
|
|||||
|
responsible for nodes allocs
|
|
|||||
|
an array of Hash_node buckets
|
|
|||||
|
desired comparison function to use
|
|
|||||
|
desired hashing function to use
|
|
|||||
|
maximum size of a data key
|
|
|||||
|
|
|
|||||
|
physical or virtual memory used
|
Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman