Annotation of parser3/src/include/pa_hash.h, revision 1.1
1.1 ! paf 1: /*
! 2: $Id: pa_string.h,v 1.1 2001/01/26 15:43:11 paf Exp $
! 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: typedef String Key;
! 21: typedef void Value;
! 22:
! 23: class Hash {
! 24: public:
! 25:
! 26: private:
! 27: friend Pool;
! 28:
! 29: // expand when there would be used this %% of size
! 30: enum {
! 31: THRESHOLD_PERCENT=75
! 32: };
! 33:
! 34: // the pool I'm allocated on
! 35: Pool *pool;
! 36:
! 37: // the index of size in sizes
! 38: int size_index;
! 39:
! 40: // possible sizes. prime numbers
! 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 {
! 55: uint code;
! 56: Key key;
! 57: Value *value;
! 58: Pair *link;
! 59: Pair(uint acode, Key& akey, Value *avalue) :
! 60: code(acode),
! 61: key(akey),
! 62: value(avalue),
! 63: link(0) {}
! 64: } **pair_refs;
! 65:
! 66: // new&constructors made private to enforce factory manufacturing at pool
! 67: static void *operator new(size_t size, Pool *apool);
! 68:
! 69: Hash(Pool *apool);
! 70:
! 71: bool full() {
! 72: return used==threshold;
! 73: }
! 74: void expand();
! 75:
! 76: public:
! 77:
! 78: Hash() { /* never */ }
! 79: static uint generic_code(uint aresult, char *start, uint size);
! 80: void put(Key& key, Value *value);
! 81: Value* get(Key& key);
! 82: };
! 83:
! 84: #endif
E-mail: