summaryrefslogtreecommitdiff
path: root/src/hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash.h')
-rw-r--r--src/hash.h53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/hash.h b/src/hash.h
index a81c355..f6c207f 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -358,6 +358,25 @@ namespace Bu
358 ); 358 );
359 } 359 }
360 } 360 }
361
362 virtual const value &get( key k ) const
363 {
364 uint32_t hash = __calcHashCode( k );
365 bool bFill;
366 uint32_t nPos = probe( hash, k, bFill );
367
368 if( bFill )
369 {
370 return aValues[nPos];
371 }
372 else
373 {
374 throw HashException(
375 excodeNotFilled,
376 "No data assosiated with that key."
377 );
378 }
379 }
361 380
362 virtual bool has( key k ) 381 virtual bool has( key k )
363 { 382 {
@@ -599,6 +618,38 @@ namespace Bu
599 bFill = false; 618 bFill = false;
600 return nCur; 619 return nCur;
601 } 620 }
621
622 uint32_t probe( uint32_t hash, key k, bool &bFill, bool rehash=true ) const
623 {
624 uint32_t nCur = hash%nCapacity;
625
626 // First we scan to see if the key is already there, abort if we
627 // run out of probing room, or we find a non-filled entry
628 for( int8_t j = 0;
629 isFilled( nCur ) && j < 32;
630 nCur = (nCur + (1<<j))%nCapacity, j++
631 )
632 {
633 // Is this the same hash code we were looking for?
634 if( hash == aHashCodes[nCur] )
635 {
636 // Skip over deleted entries. Deleted entries are also filled,
637 // so we only have to do this check here.
638 if( isDeleted( nCur ) )
639 continue;
640
641 // Is it really the same key? (for safety)
642 if( __cmpHashKeys( aKeys[nCur], k ) == true )
643 {
644 bFill = true;
645 return nCur;
646 }
647 }
648 }
649
650 bFill = false;
651 return nCur;
652 }
602 653
603 void reHash( uint32_t nNewSize ) 654 void reHash( uint32_t nNewSize )
604 { 655 {
@@ -661,7 +712,7 @@ namespace Bu
661 return (bFilled[loc/32]&(1<<(loc%32)))!=0; 712 return (bFilled[loc/32]&(1<<(loc%32)))!=0;
662 } 713 }
663 714
664 virtual bool isDeleted( uint32_t loc ) 715 virtual bool isDeleted( uint32_t loc ) const
665 { 716 {
666 return (bDeleted[loc/32]&(1<<(loc%32)))!=0; 717 return (bDeleted[loc/32]&(1<<(loc%32)))!=0;
667 } 718 }