Lines 35-42
Link Here
|
35 |
|
35 |
|
36 |
#ifndef __EST_THASH_H__ |
36 |
#ifndef __EST_THASH_H__ |
37 |
#define __EST_THASH_H__ |
37 |
#define __EST_THASH_H__ |
38 |
|
38 |
using namespace std; |
39 |
#include <iostream.h> |
39 |
#include <iostream> |
40 |
#include "EST_String.h" |
40 |
#include "EST_String.h" |
41 |
#include "EST_system.h" |
41 |
#include "EST_system.h" |
42 |
#include "EST_bool.h" |
42 |
#include "EST_bool.h" |
Lines 274-307
Link Here
|
274 |
* has a different default hash function. |
274 |
* has a different default hash function. |
275 |
*/ |
275 |
*/ |
276 |
|
276 |
|
|
|
277 |
template<class V> class EST_TStringHash; |
278 |
|
277 |
template<class V> |
279 |
template<class V> |
278 |
class EST_TStringHash : public EST_THash<EST_String, V> { |
280 |
class EST_StringHash_Pair { |
279 |
public: |
281 |
public: |
|
|
282 |
EST_String k; |
283 |
V v; |
284 |
private: |
285 |
EST_StringHash_Pair<V> *next; |
286 |
friend class EST_TStringHash<V>; |
287 |
}; |
288 |
|
289 |
template<class V> |
290 |
class EST_TStringHash : public EST_THash<EST_String, V> { |
291 |
private: |
292 |
static V Dummy_Value; |
293 |
unsigned int p_num_entries; |
294 |
unsigned int p_num_buckets; |
295 |
EST_StringHash_Pair<V> **p_buckets; |
296 |
unsigned int (*p_hash_function)(const EST_String &key, unsigned int size); |
297 |
|
298 |
protected: |
299 |
struct IPointer_s { unsigned int b; EST_StringHash_Pair<V> *p; }; |
300 |
typedef struct IPointer_s IPointer; |
301 |
void skip_blank(IPointer &ip) const |
302 |
{ |
303 |
while (ip.p==NULL && ip.b<p_num_buckets) |
304 |
{ip.b++; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0; } |
305 |
} |
306 |
|
307 |
void point_to_first(IPointer &ip) const |
308 |
{ ip.b=0; ip.p = ip.b<p_num_buckets?p_buckets[ip.b]:0; |
309 |
skip_blank(ip);} |
310 |
|
311 |
void move_pointer_forwards(IPointer &ip) const |
312 |
{ |
313 |
ip.p = ip.p->next; |
314 |
skip_blank(ip); |
315 |
} |
316 |
|
317 |
bool points_to_something(const IPointer &ip) const { return ip.b<p_num_buckets; } |
318 |
|
319 |
EST_StringHash_Pair<V> &points_at(const IPointer &ip) { return *(ip.p); } |
280 |
|
320 |
|
|
|
321 |
friend class EST_TStructIterator< EST_TStringHash<V>, IPointer, EST_StringHash_Pair<V> >; |
322 |
friend class EST_TRwStructIterator< EST_TStringHash<V>, IPointer, EST_StringHash_Pair<V> >; |
323 |
friend class EST_TIterator< EST_TStringHash<V>, IPointer, EST_StringHash_Pair<V> >; |
324 |
friend class EST_TRwIterator< EST_TStringHash<V>, IPointer, EST_StringHash_Pair<V> >; |
325 |
|
326 |
public: |
281 |
/// Create a string hash table of <parameter>size</parameter> buckets. |
327 |
/// Create a string hash table of <parameter>size</parameter> buckets. |
282 |
EST_TStringHash(int size) : EST_THash<EST_String, V>(size, StringHash) {}; |
328 |
EST_TStringHash(int size) : EST_THash<EST_String, V>(size, StringHash) {}; |
283 |
|
329 |
|
284 |
/// An entry returned by the iterator is a key value pair. |
330 |
/// An entry returned by the iterator is a key value pair. |
285 |
typedef EST_Hash_Pair<EST_String, V> Entry; |
331 |
typedef EST_StringHash_Pair<V> Entry; |
286 |
|
|
|
287 |
/* struct IPointer_s{ unsigned int b; Entry *p; }; |
288 |
typedef struct IPointer_s IPointer; */ |
289 |
|
290 |
|
332 |
|
291 |
/// Give the iterator a sensible name. |
333 |
/// Give the iterator a sensible name. |
292 |
typedef EST_TStructIterator< EST_THash<EST_String, V>, IPointer, EST_Hash_Pair<EST_String, V> > Entries; |
334 |
typedef EST_TStructIterator< EST_TStringHash<V>, IPointer, EST_StringHash_Pair<V> > Entries; |
293 |
|
335 |
typedef EST_TRwStructIterator< EST_TStringHash<V>, IPointer, EST_StringHash_Pair<V> > RwEntries; |
294 |
typedef EST_TRwStructIterator< EST_THash<EST_String, V>, IPointer, EST_Hash_Pair<EST_String, V> > RwEntries; |
|
|
295 |
//@} |
296 |
|
336 |
|
|
|
337 |
protected: |
338 |
struct IPointer_k_s { unsigned int b; EST_StringHash_Pair<V> *p; }; |
339 |
typedef struct IPointer_k_s IPointer_k; |
340 |
|
341 |
public: |
297 |
typedef EST_String KeyEntry; |
342 |
typedef EST_String KeyEntry; |
298 |
|
343 |
|
299 |
/* struct IPointer_k_s { unsigned int b; EST_Hash_Pair<EST_String, V> *p; }; |
|
|
300 |
typedef struct IPointer_k_s IPointer_k; */ |
301 |
|
302 |
/// Give the iterator a sensible name. |
344 |
/// Give the iterator a sensible name. |
303 |
typedef EST_TIterator< EST_THash<EST_String, V>, IPointer_k, EST_String > KeyEntries; |
345 |
typedef EST_TIterator< EST_TStringHash<V>, IPointer_k, EST_String > KeyEntries; |
304 |
typedef EST_TRwIterator< EST_THash<EST_String, V>, IPointer_k, EST_String > KeyRwEntries; |
346 |
typedef EST_TRwIterator< EST_TStringHash<V>, IPointer_k, EST_String > KeyRwEntries; |
305 |
}; |
347 |
}; |
306 |
|
348 |
|
307 |
|
349 |
|