Hash Table


An associative container (hash table) supporting all functionality for a compiler symbol table. Collisions are kept is a linked list.

The class instantiating the template parameter must a method as follows : "operator const char* (void) const;". This is the conversion operator used by the supplied hash function. You can define your own hash function.

Library

ETL<ToolKit>

Declaration


#include<ospace/advanced/Hash.h>

template
  <
  class Instantiator
  >
class os_Hash

Interface

Constructor
os_Hash( int table_size = 97, os_HashFun hash = 0)
This the default constructor which can also accept a size and your hash function. The constructor uses internal hasher when the second argument is 0 (the default value).
Destructor
~os_Hash()
Destroys all entries in the table.
=
os_Hash<T>& operator=(const os_Hash<T>&)
The assignment operator .
make_empty
os_Hash<T>& make_empty(void)
Removes and destroys the contents. The hash table is in state of initial construction.
Size
unsigned int Size(void)
Returns the number of items in the table.
insert
os_Hash<T>& insert(const T& item)
Adds the item to the table.
remove
os_Hash<T>& remove(const T& item)
Removes the most recent occurrence of item from the table.
remove_all
os_Hash<T>& remove_all(const T& item)
Removes all occurrences of item from the table.
remove
os_Hash<T>& remove(const char* name)
Same as remove above, using the key to reach item.
remove_all
os_Hash<T>& remove_all(const char* n)
Same as remove_all above, using the key to reach item.
exists
int exists(const T& item)
Returns 1 (true) if item is in table. Otherwise returns 0 (false).
exists
int exists(const char* name)
Same as above using the key .
top
const T& top(void)
When exists method returns TRUE, top returns a const reference to the item.
head
T& head(void)
Same as top except the reference is not const, so the item can be modified.
entity
T& entity(const T& item)
For an item already in table, returns a reference to the item. The item can be modified.
entity
T& entity(const char* name)
Same as entity above, using the key.
number
int number(const T& item)
Number of occurrence of item in the table.
number
int number(const char* n)
Same as number above, using the key.
Member
T& Member(const T& item, int number)
Returns a reference to the "number"-th occurrence of item in table. Item can be modified.
Member
T& Member(const char* name, int number)
Same as Member above, using the key.

Copyright©2005-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.