36 #ifndef __EST_THASH_H__
37 #define __EST_THASH_H__
43 #include "EST_String.h"
44 #include "EST_system.h"
46 #include "EST_TIterator.h"
48 #include "instantiate/EST_THashI.h"
49 #include "instantiate/EST_TStringHashI.h"
65 static unsigned int DefaultHash(
const void *data,
size_t size,
unsigned int n);
68 static unsigned int StringHash(
const EST_String &key,
unsigned int size);
77 template<
class K,
class V>
98 template<
class K,
class V>
103 static V Dummy_Value;
107 unsigned int p_num_entries;
110 unsigned int p_num_buckets;
116 unsigned int (*p_hash_function)(
const K &key,
unsigned int size);
123 unsigned int (*hash_function)(
const K &key,
unsigned int size)= NULL);
136 {
return p_num_entries; };
139 int present(
const K &key)
const;
144 V &val(
const K &key,
int &found)
const;
147 V &
val(
const K &key)
const {
int x;
return val(key, x); }
149 const K &key(
const V &val,
int &found)
const;
150 const K &key(
const V &val)
const {
int x;
return key(val, x); }
156 void map(
void (*func)(K&, V&));
159 int add_item(
const K &key,
const V &value,
int no_search = 0);
162 int remove_item(
const K &rkey,
int quiet = 0);
168 void dump(ostream &stream,
int all=0);
187 while (ip.p==NULL && ip.b<p_num_buckets)
188 {ip.b++; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0; }
193 { ip.b=0; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0;
240 while (ip.p==NULL && ip.b<p_num_buckets)
241 {ip.b++; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0; }
246 { ip.b=0; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0;
260 K &
points_at(
const IPointer_k &ip) {
return (ip.p)->k; }
326 inline static unsigned int DefaultHashFunction(
const void *data,
size_t size,
unsigned int n)
329 const char *p = (
const char *)data;
330 for(; size>0 ; p++, size--)
EST_TStructIterator< EST_THash< K, V >, IPointer, EST_Hash_Pair< K, V > > Entries
Give the iterator a sensible name.
An open hash table. The number of buckets should be set to allow enough space that there are relative...
void skip_blank(IPointer &ip) const
Shift to point at something.
EST_TStructIterator< EST_THash< EST_String, V >, typename EST_THash< EST_String, V >::IPointer, EST_Hash_Pair< EST_String, V > > Entries
Give the iterator a sensible name.
A specialised hash table for when the key is an EST_String.
bool points_to_something(const IPointer &ip) const
We are at the end if the pointer ever becomes NULL.
void point_to_first(IPointer_k &ip) const
Go to start of the table.
EST_TIterator< EST_THash< K, V >, IPointer_k, K > KeyEntries
Give the iterator a sensible name.
K & points_at(const IPointer_k &ip)
Return the key of this entry.
EST_TStringHash(int size)
Create a string hash table of size buckets.
void skip_blank(IPointer_k &ip) const
Shift to point at something.
void point_to_first(IPointer &ip) const
Go to start of the table.
EST_THash< EST_String, V >::IPointer_k TN_IPointer_k
Give the iterator a sensible name.
EST_Hash_Pair< K, V > Entry
An entry returned by the iterator is a key value pair.
V & val(const K &key) const
Return the value associated with the key.
unsigned int num_entries(void) const
Return the total number of entries in the table.
This is just a convenient place to put some useful hash functions.
EST_Hash_Pair< K, V > & points_at(const IPointer &ip)
Return the contents of this entry.
void move_pointer_forwards(IPointer_k &ip) const
Move pointer forwards, at the end of the bucket, move down.
void move_pointer_forwards(IPointer &ip) const
Move pointer forwards, at the end of the bucket, move down.
This class is used in hash tables to hold a key value pair. Not much to say beyond that...
bool points_to_something(const IPointer_k &ip) const
We are at the end if the pointer ever becomes NULL.
K KeyEntry
An entry returned by this iterator is just a key.