Annotation of parser3/src/include/pa_hash.h, revision 1.3

1.1       paf         1: /*
1.3     ! paf         2:   $Id: pa_hash.h,v 1.2 2001/01/27 12:04:53 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: 
                     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 {
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: 
                     76:        bool full() {
                     77:                return used==threshold;
                     78:        }
                     79:        void expand();
                     80: 
                     81: public:
                     82: 
                     83:        static uint generic_code(uint aresult, char *start, uint size);
                     84:        void put(Key& key, Value *value);
                     85:        Value* get(Key& key);
                     86: };
                     87: 
                     88: #endif

E-mail: