36 #ifndef __EST_THASH_H__ 37 #define __EST_THASH_H__ 75 template<
class K,
class V>
102 template<
class K,
class V>
107 static V Dummy_Value;
111 unsigned int p_num_entries;
114 unsigned int p_num_buckets;
120 unsigned int (*p_hash_function)(
const K &key,
unsigned int size);
127 unsigned int (*hash_function)(
const K &key,
unsigned int size)=
NULL);
140 {
return p_num_entries; };
143 int present(
const K &key)
const;
148 V &
val(
const K &key,
int &found)
const;
151 V &
val(
const K &key)
const {
int x;
return val(key, x); }
153 const K &key(
const V &val,
int &found)
const;
154 const K &
key(
const V &val)
const {
int x;
return key(val, x); }
160 void map(
void (*func)(K&, V&));
163 int add_item(
const K &key,
const V &value,
int no_search = 0);
172 void dump(ostream &stream,
int all=0);
199 while (ip.p==
NULL && ip.b<p_num_buckets)
200 {ip.b++; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0; }
205 { ip.b=0; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0;
260 while (ip.p==
NULL && ip.b<p_num_buckets)
261 {ip.b++; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0; }
266 { ip.b=0; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0;
280 K &
points_at(
const IPointer_k &ip) {
return (ip.p)->k; }
346 inline static unsigned int DefaultHashFunction(
const void *data,
ssize_t size,
unsigned int n)
349 const char *p = (
const char *)data;
350 for(; size>0 ; p++, size--)
static unsigned int DefaultHash(const void *data, ssize_t size, unsigned int n)
A generally useful hash function.
EST_Hash_Pair< K, V > * p
EST_Hash_Pair()
A constructor:
EST_TIterator< EST_THash< K, V >, IPointer_k, K > KeyEntries
Give the iterator a sensible name.
EST_TRwStructIterator< EST_THash< K, V >, IPointer, EST_Hash_Pair< K, V > > RwEntries
EST_TStructIterator< EST_THash< K, V >, IPointer, EST_Hash_Pair< K, V > > Entries
Give the iterator a sensible name.
unsigned int num_entries(void) const
Return the total number of entries in the table.
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.
EST_TRwIterator< EST_THash< K, V >, IPointer_k, K > KeyRwEntries
void skip_blank(IPointer_k &ip) const
Shift to point at something.
EST_TStringHash(int size)
Create a string hash table of size buckets.
void point_to_first(IPointer_k &ip) const
Go to start of the table.
bool points_to_something(const IPointer_k &ip) const
We are at the end if the pointer ever becomes NULL.
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.
void point_to_first(IPointer &ip) const
Go to start of the table.
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.
K & points_at(const IPointer_k &ip)
Return the key of this entry.
EST_TVector< T > & copy(EST_TVector< T > a, const EST_TList< T > &in)
This is just a convenient place to put some useful hash functions.
V & val(const K &key) const
Return the value associated with the key.
static unsigned int StringHash(const EST_String &key, unsigned int size)
A hash function for strings.
void skip_blank(IPointer &ip) const
Shift to point at something.
const K & key(const V &val) const
EST_Hash_Pair< K, V > * p
EST_TIterator< EST_THash< EST_String, V >, typename EST_THash< EST_String, V >::IPointer_k, EST_String > KeyEntries
An open hash table. The number of buckets should be set to allow enough space that there are relative...
EST_TRwIterator< EST_THash< EST_String, V >, typename EST_THash< EST_String, V >::IPointer_k, EST_String > KeyRwEntries
EST_THash< EST_String, V >::IPointer TN_IPointer
EST_Hash_Pair< K, V > Entry
An entry returned by the iterator is a key value pair.
void remove_item(EST_Item *l, const char *relname)
EST_Hash_Pair< K, V > & points_at(const IPointer &ip)
Return the contents of this entry.
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 &ip) const
We are at the end if the pointer ever becomes NULL.
EST_TRwStructIterator< EST_THash< EST_String, V >, typename EST_THash< EST_String, V >::IPointer, EST_Hash_Pair< EST_String, V > > RwEntries