summaryrefslogtreecommitdiff
path: root/src/hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash.h')
-rw-r--r--src/hash.h46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/hash.h b/src/hash.h
index d53e2be..cd21a29 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -92,7 +92,10 @@ public:
92 void erase() 92 void erase()
93 { 93 {
94 if( bFilled ) 94 if( bFilled )
95 {
95 hsh._erase( nPos ); 96 hsh._erase( nPos );
97 hsh.onDelete();
98 }
96 } 99 }
97 100
98 _value operator=( _value nval ) 101 _value operator=( _value nval )
@@ -101,10 +104,12 @@ public:
101 { 104 {
102 hsh.va.destroy( pValue ); 105 hsh.va.destroy( pValue );
103 hsh.va.construct( pValue, nval ); 106 hsh.va.construct( pValue, nval );
107 hsh.onUpdate();
104 } 108 }
105 else 109 else
106 { 110 {
107 hsh.fill( nPos, *pKey, nval, hash ); 111 hsh.fill( nPos, *pKey, nval, hash );
112 hsh.onInsert();
108 } 113 }
109 114
110 return nval; 115 return nval;
@@ -174,7 +179,7 @@ public:
174 return nDeleted; 179 return nDeleted;
175 } 180 }
176 181
177 HashProxy<key, value, sizecalc, keyalloc, valuealloc, challoc> operator[]( key k ) 182 virtual HashProxy<key, value, sizecalc, keyalloc, valuealloc, challoc> operator[]( key k )
178 { 183 {
179 uint32_t hash = __calcHashCode( k ); 184 uint32_t hash = __calcHashCode( k );
180 bool bFill; 185 bool bFill;
@@ -190,7 +195,7 @@ public:
190 } 195 }
191 } 196 }
192 197
193 void insert( key k, value v ) 198 virtual void insert( key k, value v )
194 { 199 {
195 uint32_t hash = __calcHashCode( k ); 200 uint32_t hash = __calcHashCode( k );
196 bool bFill; 201 bool bFill;
@@ -200,14 +205,16 @@ public:
200 { 205 {
201 va.destroy( &aValues[nPos] ); 206 va.destroy( &aValues[nPos] );
202 va.construct( &aValues[nPos], v ); 207 va.construct( &aValues[nPos], v );
208 onUpdate();
203 } 209 }
204 else 210 else
205 { 211 {
206 fill( nPos, k, v, hash ); 212 fill( nPos, k, v, hash );
213 onInsert();
207 } 214 }
208 } 215 }
209 216
210 void erase( key k ) 217 virtual void erase( key k )
211 { 218 {
212 uint32_t hash = __calcHashCode( k ); 219 uint32_t hash = __calcHashCode( k );
213 bool bFill; 220 bool bFill;
@@ -216,10 +223,11 @@ public:
216 if( bFill ) 223 if( bFill )
217 { 224 {
218 _erase( nPos ); 225 _erase( nPos );
226 onDelete();
219 } 227 }
220 } 228 }
221 229
222 void clear() 230 virtual void clear()
223 { 231 {
224 for( uint32_t j = 0; j < nCapacity; j++ ) 232 for( uint32_t j = 0; j < nCapacity; j++ )
225 { 233 {
@@ -228,13 +236,14 @@ public:
228 { 236 {
229 va.destroy( &aValues[j] ); 237 va.destroy( &aValues[j] );
230 ka.destroy( &aKeys[j] ); 238 ka.destroy( &aKeys[j] );
239 onDelete();
231 } 240 }
232 } 241 }
233 242
234 clearBits(); 243 clearBits();
235 } 244 }
236 245
237 value get( key k ) 246 virtual value get( key k )
238 { 247 {
239 uint32_t hash = __calcHashCode( k ); 248 uint32_t hash = __calcHashCode( k );
240 bool bFill; 249 bool bFill;
@@ -253,7 +262,7 @@ public:
253 } 262 }
254 } 263 }
255 264
256 bool has( key k ) 265 virtual bool has( key k )
257 { 266 {
258 bool bFill; 267 bool bFill;
259 probe( __calcHashCode( k ), k, bFill ); 268 probe( __calcHashCode( k ), k, bFill );
@@ -338,8 +347,13 @@ public:
338 return iterator( *this, true ); 347 return iterator( *this, true );
339 } 348 }
340 349
341private: 350protected:
342 void clearBits() 351 virtual void onInsert() {}
352 virtual void onUpdate() {}
353 virtual void onDelete() {}
354 virtual void onReHash() {}
355
356 virtual void clearBits()
343 { 357 {
344 for( uint32_t j = 0; j < nKeysSize; j++ ) 358 for( uint32_t j = 0; j < nKeysSize; j++ )
345 { 359 {
@@ -347,7 +361,7 @@ private:
347 } 361 }
348 } 362 }
349 363
350 void fill( uint32_t loc, key &k, value &v, uint32_t hash ) 364 virtual void fill( uint32_t loc, key &k, value &v, uint32_t hash )
351 { 365 {
352 bFilled[loc/32] |= (1<<(loc%32)); 366 bFilled[loc/32] |= (1<<(loc%32));
353 va.construct( &aValues[loc], v ); 367 va.construct( &aValues[loc], v );
@@ -356,19 +370,19 @@ private:
356 nFilled++; 370 nFilled++;
357 } 371 }
358 372
359 void _erase( uint32_t loc ) 373 virtual void _erase( uint32_t loc )
360 { 374 {
361 bDeleted[loc/32] |= (1<<(loc%32)); 375 bDeleted[loc/32] |= (1<<(loc%32));
362 va.destroy( &aValues[loc] ); 376 va.destroy( &aValues[loc] );
363 ka.destroy( &aKeys[loc] ); 377 ka.destroy( &aKeys[loc] );
364 } 378 }
365 379
366 std::pair<key,value> getAtPos( uint32_t nPos ) 380 virtual std::pair<key,value> getAtPos( uint32_t nPos )
367 { 381 {
368 return std::pair<key,value>(aKeys[nPos],aValues[nPos]); 382 return std::pair<key,value>(aKeys[nPos],aValues[nPos]);
369 } 383 }
370 384
371 uint32_t getFirstPos( bool &bFinished ) 385 virtual uint32_t getFirstPos( bool &bFinished )
372 { 386 {
373 for( uint32_t j = 0; j < nCapacity; j++ ) 387 for( uint32_t j = 0; j < nCapacity; j++ )
374 { 388 {
@@ -381,7 +395,7 @@ private:
381 return 0; 395 return 0;
382 } 396 }
383 397
384 uint32_t getNextPos( uint32_t nPos, bool &bFinished ) 398 virtual uint32_t getNextPos( uint32_t nPos, bool &bFinished )
385 { 399 {
386 for( uint32_t j = nPos+1; j < nCapacity; j++ ) 400 for( uint32_t j = nPos+1; j < nCapacity; j++ )
387 { 401 {
@@ -488,17 +502,17 @@ private:
488 ca.deallocate( aOldHashCodes, nOldCapacity ); 502 ca.deallocate( aOldHashCodes, nOldCapacity );
489 } 503 }
490 504
491 bool isFilled( uint32_t loc ) 505 virtual bool isFilled( uint32_t loc )
492 { 506 {
493 return (bFilled[loc/32]&(1<<(loc%32)))!=0; 507 return (bFilled[loc/32]&(1<<(loc%32)))!=0;
494 } 508 }
495 509
496 bool isDeleted( uint32_t loc ) 510 virtual bool isDeleted( uint32_t loc )
497 { 511 {
498 return (bDeleted[loc/32]&(1<<(loc%32)))!=0; 512 return (bDeleted[loc/32]&(1<<(loc%32)))!=0;
499 } 513 }
500 514
501private: 515protected:
502 uint32_t nCapacity; 516 uint32_t nCapacity;
503 uint32_t nFilled; 517 uint32_t nFilled;
504 uint32_t nDeleted; 518 uint32_t nDeleted;