equal
deleted
inserted
replaced
52 // The list starts with a count. A hash lookup finds the list head, then a |
52 // The list starts with a count. A hash lookup finds the list head, then a |
53 // simple linear scan finds the key. If the table gets too full, it's |
53 // simple linear scan finds the key. If the table gets too full, it's |
54 // doubled in size; the total amount of EXTRA times all hash functions are |
54 // doubled in size; the total amount of EXTRA times all hash functions are |
55 // computed for the doubling is no more than the current size - thus the |
55 // computed for the doubling is no more than the current size - thus the |
56 // doubling in size costs no more than a constant factor in speed. |
56 // doubling in size costs no more than a constant factor in speed. |
57 Dict::Dict(CmpKey initcmp, Hash inithash) : _hash(inithash), _cmp(initcmp), |
57 Dict::Dict(CmpKey initcmp, Hash inithash) : _arena(Thread::current()->resource_area()), |
58 _arena(Thread::current()->resource_area()) { |
58 _hash(inithash), _cmp(initcmp) { |
59 int i; |
59 int i; |
60 |
60 |
61 // Precompute table of null character hashes |
61 // Precompute table of null character hashes |
62 if( !initflag ) { // Not initializated yet? |
62 if( !initflag ) { // Not initializated yet? |
63 xsum[0] = (1<<shft[0])+1; // Initialize |
63 xsum[0] = (1<<shft[0])+1; // Initialize |
72 _bin = (bucket*)_arena->Amalloc_4(sizeof(bucket)*_size); |
72 _bin = (bucket*)_arena->Amalloc_4(sizeof(bucket)*_size); |
73 memset((void*)_bin,0,sizeof(bucket)*_size); |
73 memset((void*)_bin,0,sizeof(bucket)*_size); |
74 } |
74 } |
75 |
75 |
76 Dict::Dict(CmpKey initcmp, Hash inithash, Arena *arena, int size) |
76 Dict::Dict(CmpKey initcmp, Hash inithash, Arena *arena, int size) |
77 : _hash(inithash), _cmp(initcmp), _arena(arena) { |
77 : _arena(arena), _hash(inithash), _cmp(initcmp) { |
78 int i; |
78 int i; |
79 |
79 |
80 // Precompute table of null character hashes |
80 // Precompute table of null character hashes |
81 if( !initflag ) { // Not initializated yet? |
81 if( !initflag ) { // Not initializated yet? |
82 xsum[0] = (1<<shft[0])+1; // Initialize |
82 xsum[0] = (1<<shft[0])+1; // Initialize |
159 } // End of for all buckets |
159 } // End of for all buckets |
160 } |
160 } |
161 |
161 |
162 //------------------------------Dict----------------------------------------- |
162 //------------------------------Dict----------------------------------------- |
163 // Deep copy a dictionary. |
163 // Deep copy a dictionary. |
164 Dict::Dict( const Dict &d ) : _size(d._size), _cnt(d._cnt), _hash(d._hash),_cmp(d._cmp), _arena(d._arena) { |
164 Dict::Dict( const Dict &d ) : _arena(d._arena), _size(d._size), _cnt(d._cnt), _hash(d._hash), _cmp(d._cmp) { |
165 _bin = (bucket*)_arena->Amalloc_4(sizeof(bucket)*_size); |
165 _bin = (bucket*)_arena->Amalloc_4(sizeof(bucket)*_size); |
166 memcpy( (void*)_bin, (void*)d._bin, sizeof(bucket)*_size ); |
166 memcpy( (void*)_bin, (void*)d._bin, sizeof(bucket)*_size ); |
167 for( uint i=0; i<_size; i++ ) { |
167 for( uint i=0; i<_size; i++ ) { |
168 if( !_bin[i]._keyvals ) continue; |
168 if( !_bin[i]._keyvals ) continue; |
169 _bin[i]._keyvals=(void**)_arena->Amalloc_4( sizeof(void *)*_bin[i]._max*2); |
169 _bin[i]._keyvals=(void**)_arena->Amalloc_4( sizeof(void *)*_bin[i]._max*2); |