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);
69template<
class K,
class V>
class EST_THash;
74template<
class K,
class V>
95template<
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; };
141 V &val(
const K &key,
int &
found)
const;
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&));
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;
323inline 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--)
static unsigned int DefaultHash(const void *data, size_t size, unsigned int n)
A generally useful hash function.
static unsigned int StringHash(const EST_String &key, unsigned int size)
A hash function for strings.
void move_pointer_forwards(IPointer_k &ip) const
Move pointer forwards, at the end of the bucket, move down.
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.
void copy(const EST_THash< K, V > &from)
Copy all entries.
void skip_blank(IPointer_k &ip) const
Shift to point at something.
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.
K KeyEntry
An entry returned by this iterator is just a key.
void move_pointer_forwards(IPointer &ip) const
Move pointer forwards, at the end of the bucket, move down.
void dump(ostream &stream, int all=0)
Print the table to <parameter>stream</parameter> in a human readable format.
bool points_to_something(const IPointer &ip) const
We are at the end if the pointer ever becomes NULL.
void map(void(*func)(K &, V &))
Apply <parameter>func</parameter> to each entry in the table.
EST_Hash_Pair< K, V > & points_at(const IPointer &ip)
Return the contents of this entry.
int add_item(const K &key, const V &value, int no_search=0)
Add an entry to the table.
bool points_to_something(const IPointer_k &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.
int present(const K &key) const
Does the key have an entry?
void clear(void)
Empty the table.
EST_TStructIterator< EST_THash< K, V >, IPointer, EST_Hash_Pair< K, V > > Entries
Give the iterator a sensible name.
~EST_THash(void)
Destroy the table.
void point_to_first(IPointer &ip) const
Go to start of the table.
void skip_blank(IPointer &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.
EST_Hash_Pair< EST_String, V > Entry
An entry returned by the iterator is a key value pair.
EST_THash< EST_String, V >::IPointer_k TN_IPointer_k
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.
EST_TStringHash(int size)
Create a string hash table of <parameter>size</parameter> buckets.