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" 63 static unsigned int DefaultHash(
const void *data,
size_t size,
unsigned int n);
66 static unsigned int StringHash(
const EST_String &key,
unsigned int size);
74 template<
class K,
class V>
95 template<
class K,
class V>
100 static V Dummy_Value;
104 unsigned int p_num_entries;
107 unsigned int p_num_buckets;
113 unsigned int (*p_hash_function)(
const K &key,
unsigned int size);
120 unsigned int (*hash_function)(
const K &key,
unsigned int size)= NULL);
133 {
return p_num_entries; };
136 int present(
const K &key)
const;
141 V &val(
const K &key,
int &found)
const;
144 V &
val(
const K &key)
const {
int x;
return val(key, x); }
146 const K &key(
const V &val,
int &found)
const;
147 const K &key(
const V &val)
const {
int x;
return key(val, x); }
153 void map(
void (*func)(K&, V&));
156 int add_item(
const K &key,
const V &value,
int no_search = 0);
159 int remove_item(
const K &rkey,
int quiet = 0);
165 void dump(ostream &stream,
int all=0);
184 while (ip.p==NULL && ip.b<p_num_buckets)
185 {ip.b++; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0; }
190 { ip.b=0; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0;
237 while (ip.p==NULL && ip.b<p_num_buckets)
238 {ip.b++; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0; }
243 { ip.b=0; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0;
257 K &
points_at(
const IPointer_k &ip) {
return (ip.p)->k; }
323 inline static unsigned int DefaultHashFunction(
const void *data,
size_t size,
unsigned int n)
326 const char *p = (
const char *)data;
327 for(; size>0 ; p++, size--)
EST_TIterator< EST_THash< K, V >, IPointer_k, K > KeyEntries
Give the iterator a sensible name.
EST_TStructIterator< EST_THash< K, V >, IPointer, EST_Hash_Pair< K, V > > Entries
Give the iterator a sensible name.
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.
void move_pointer_forwards(IPointer &ip) const
Move pointer forwards, at the end of the bucket, move down.
EST_TStringHash(int size)
Create a string hash table of <parameter>size</parameter> buckets.
void point_to_first(IPointer_k &ip) const
Go to start of the table.
EST_THash< EST_String, V >::IPointer_k TN_IPointer_k
Give the iterator a sensible name.
K KeyEntry
An entry returned by this iterator is just a key.
K & points_at(const IPointer_k &ip)
Return the key of this entry.
bool points_to_something(const IPointer &ip) const
We are at the end if the pointer ever becomes NULL.
V & val(const K &key) const
Return the value associated with the key.
void move_pointer_forwards(IPointer_k &ip) const
Move pointer forwards, at the end of the bucket, move down.
void skip_blank(IPointer_k &ip) const
Shift to point at something.
EST_Hash_Pair< K, V > Entry
An entry returned by the iterator is a key value pair.
unsigned int num_entries(void) const
Return the total number of entries in the table.
bool points_to_something(const IPointer_k &ip) const
We are at the end if the pointer ever becomes NULL.
EST_Hash_Pair< K, V > & points_at(const IPointer &ip)
Return the contents of this entry.
void point_to_first(IPointer &ip) const
Go to start of the table.
void skip_blank(IPointer &ip) const
Shift to point at something.