Annotation of parser3/src/include/pa_hash.h, revision 1.10
1.1 paf 1: /*
1.10 ! paf 2: $Id: pa_hash.h,v 1.9 2001/01/29 12:13:14 paf Exp $
1.1 paf 3: */
4:
5: /*
6:
7:
8: */
9:
10: #ifndef PA_HASH_H
11: #define PA_HASH_H
12:
13: #include <stddef.h>
14:
15: #include "pa_types.h"
16: #include "pa_string.h"
17:
18: class Pool;
19:
20: class Hash {
21: public:
22:
1.3 paf 23: typedef String Key;
24: typedef void Value;
25:
1.8 paf 26: public:
27:
1.10 ! paf 28: void *operator new(size_t size, Pool *apool);
! 29: Hash(Pool *apool, bool athread_safe);
! 30:
1.8 paf 31: // useful generic hash function
32: static uint generic_code(uint aresult, char *start, uint size);
33:
34: // put a [value] under the [key]
35: /*SYNCHRONIZED*/ void put(Key& key, Value *value);
36:
37: // get associated [value] by the [key]
38: /*SYNCHRONIZED*/ Value* get(Key& key);
39:
1.10 ! paf 40: protected:
! 41:
! 42: // the pool I'm allocated on
! 43: Pool *pool;
! 44:
1.1 paf 45: private:
46:
1.6 paf 47: // expand when these %% of size exausted
1.1 paf 48: enum {
49: THRESHOLD_PERCENT=75
50: };
51:
1.9 paf 52: // am I thread-safe?
53: bool thread_safe;
54:
1.5 paf 55: // the index of [size] in [sizes]
1.1 paf 56: int size_index;
57:
1.5 paf 58: // possible [sizes]. prime numbers
1.1 paf 59: static uint sizes[];
60: static int sizes_count;
61:
62: // number of allocated pairs
63: int size;
64:
65: // helper: expanding when used == threshold
66: int threshold;
67:
68: // used pairs
69: int used;
70:
71: // main storage
72: class Pair {
1.2 paf 73: friend Hash;
74:
1.1 paf 75: uint code;
76: Key key;
77: Value *value;
78: Pair *link;
1.2 paf 79:
80: void *operator new(size_t size, Pool *apool);
81:
82: Pair(uint acode, Key& akey, Value *avalue, Pair *alink) :
1.1 paf 83: code(acode),
84: key(akey),
85: value(avalue),
1.2 paf 86: link(alink) {}
87: } **refs;
1.1 paf 88:
1.5 paf 89: // filled to threshold: needs expanding
90: bool full() { return used==threshold; }
91:
92: // allocate larger buffer & rehash
1.1 paf 93: void expand();
1.4 paf 94:
95: private: //disabled
96:
1.10 ! paf 97: Hash(Hash&) {}
! 98: Hash& operator = (Hash&) { return *this; }
1.1 paf 99: };
100:
101: #endif
E-mail: