Annotation of parser3/src/include/pa_hash.h, revision 1.5
1.1 paf 1: /*
1.5 ! paf 2: $Id: pa_hash.h,v 1.4 2001/01/27 15:21:05 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.1 paf 26: private:
27: friend Pool;
28:
1.3 paf 29: // expand when used these %% of size
1.1 paf 30: enum {
31: THRESHOLD_PERCENT=75
32: };
33:
34: // the pool I'm allocated on
35: Pool *pool;
36:
1.5 ! paf 37: // the index of [size] in [sizes]
1.1 paf 38: int size_index;
39:
1.5 ! paf 40: // possible [sizes]. prime numbers
1.1 paf 41: static uint sizes[];
42: static int sizes_count;
43:
44: // number of allocated pairs
45: int size;
46:
47: // helper: expanding when used == threshold
48: int threshold;
49:
50: // used pairs
51: int used;
52:
53: // main storage
54: class Pair {
1.2 paf 55: friend Hash;
56:
1.1 paf 57: uint code;
58: Key key;
59: Value *value;
60: Pair *link;
1.2 paf 61:
62: void *operator new(size_t size, Pool *apool);
63:
64: Pair(uint acode, Key& akey, Value *avalue, Pair *alink) :
1.1 paf 65: code(acode),
66: key(akey),
67: value(avalue),
1.2 paf 68: link(alink) {}
69: } **refs;
1.1 paf 70:
71: // new&constructors made private to enforce factory manufacturing at pool
1.2 paf 72: void *operator new(size_t size, Pool *apool);
1.1 paf 73:
74: Hash(Pool *apool);
75:
1.5 ! paf 76: // filled to threshold: needs expanding
! 77: bool full() { return used==threshold; }
! 78:
! 79: // allocate larger buffer & rehash
1.1 paf 80: void expand();
81:
82: public:
83:
1.5 ! paf 84: // useful generic hash function
1.1 paf 85: static uint generic_code(uint aresult, char *start, uint size);
1.5 ! paf 86:
! 87: // put a [value] under the [key]
1.1 paf 88: void put(Key& key, Value *value);
1.5 ! paf 89:
! 90: // get associated [value] by the [key]
1.1 paf 91: Value* get(Key& key);
1.4 paf 92:
93: private: //disabled
94:
95: Hash& operator = (Hash& src) { return *this; }
96: Hash(Hash& src) {}
1.1 paf 97: };
98:
99: #endif
E-mail: