44template<
class K,
class V>
52 for(
int i=0; i<size;i++)
55 p_hash_function = hash_function;
58template<
class K,
class V>
65template<
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)
84template<
class K,
class V>
95template<
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)
113template<
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)
135template<
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)
153template<
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)
166template<
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];
194template<
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 cerr <<
"THash: no item labelled \"" << rkey <<
"\"" << endl;
220template<
class K,
class V>
227template<
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 <<
") ";
241template<
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 copy(const EST_THash< K, V > &from)
Copy all entries.
EST_THash(int size, unsigned int(*hash_function)(const K &key, unsigned int size)=NULL)
EST_THash< K, V > & operator=(const EST_THash< K, V > &from)
Assignment is a copy operation.
int remove_item(const K &rkey, int quiet=0)
Remove an entry from the table.
V & val(const K &key, int &found) const
void dump(ostream &stream, int all=0)
Print the table to <parameter>stream</parameter> in a human readable format.
void map(void(*func)(K &, V &))
Apply <parameter>func</parameter> to each entry in the table.
int add_item(const K &key, const V &value, int no_search=0)
Add an entry to the table.
int present(const K &key) const
Does the key have an entry?
void clear(void)
Empty the table.
~EST_THash(void)
Destroy the table.