44 template<
class K,
class V>
52 for(
int i=0; i<size;i++)
55 p_hash_function = hash_function;
58 template<
class K,
class V>
65 template<
class K,
class V>
68 if (p_buckets !=
NULL)
70 for(
unsigned int i=0; i<p_num_buckets;i++)
73 for(p=p_buckets[i]; p !=
NULL; p=n)
84 template<
class K,
class V>
95 template<
class K,
class V>
100 b = (*p_hash_function)(key, p_num_buckets);
102 b = DefaultHashFunction((
void *)&key,
sizeof(key), p_num_buckets);
106 for(p=p_buckets[b]; p!=
NULL; p=p->next)
113 template<
class K,
class V>
118 b = (*p_hash_function)(key, p_num_buckets);
120 b = DefaultHashFunction((
void *)&key,
sizeof(key), p_num_buckets);
124 for(p=p_buckets[b]; p!=
NULL; p=p->next)
135 template<
class K,
class V>
139 for(
unsigned int b=0; b<p_num_buckets; b++)
142 for(p=p_buckets[b]; p!=
NULL; p=p->next)
153 template<
class K,
class V>
156 for(
unsigned int i=0; i<p_num_buckets; i++)
160 for(p=p_buckets[i]; p!=
NULL; p=p->next)
166 template<
class K,
class V>
171 b = (*p_hash_function)(key, p_num_buckets);
173 b = DefaultHashFunction((
void *)&key,
sizeof(key), p_num_buckets);
178 for(p=p_buckets[b]; p!=
NULL; p=p->next)
188 p->next = p_buckets[b];
194 template<
class K,
class V>
199 b = (*p_hash_function)(rkey, p_num_buckets);
201 b = DefaultHashFunction((
void *)&rkey,
sizeof(rkey), p_num_buckets);
205 for (p = &(p_buckets[b]); *p!=
NULL; p=&((*p)->next))
206 if ( (*p)->k == rkey )
216 std::cerr <<
"THash: no item labelled \"" << rkey <<
"\"" << std::endl;
220 template<
class K,
class V>
227 template<
class K,
class V>
230 for(
unsigned int i=0; i<p_num_buckets; i++)
231 if (all || p_buckets[i])
235 for(p=p_buckets[i]; p!=
NULL; p=p->next)
236 stream <<
"[" << p->
k <<
"],(" << p->
v <<
") ";
241 template<
class K,
class V>
245 p_num_entries = from.p_num_entries;
246 p_num_buckets = from.p_num_buckets;
247 p_hash_function = from.p_hash_function;
249 if (p_buckets !=
NULL)
255 for(
unsigned int b=0; b<p_num_buckets; b++)
261 n->next = p_buckets[b];
void clear(void)
Empty the table.
EST_THash(int size, unsigned int(*hash_function)(const K &key, unsigned int size)=NULL)
void copy(const EST_THash< K, V > &from)
Copy all entries.
void map(void(*func)(K &, V &))
Apply func to each entry in the table.
int remove_item(const K &rkey, int quiet=0)
Remove an entry from the table.
~EST_THash(void)
Destroy the table.
EST_THash< K, V > & operator=(const EST_THash< K, V > &from)
Assignment is a copy operation.
V & val(const K &key, int &found) const
int present(const K &key) const
Does the key have an entry?
const K & key(const V &val, int &found) const
EST_TVector< T > & copy(EST_TVector< T > a, const EST_TList< T > &in)
int add_item(const K &key, const V &value, int no_search=0)
Add an entry to the table.
An open hash table. The number of buckets should be set to allow enough space that there are relative...
void dump(ostream &stream, int all=0)
Print the table to stream in a human readable format.
This class is used in hash tables to hold a key value pair. Not much to say beyond that...