aboutsummaryrefslogtreecommitdiff
path: root/src/hash.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-07 04:55:29 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-07 04:55:29 +0000
commitc2e3879b965d297604804f03271ac71c8c5c81f3 (patch)
treee3abe738a7aca61fc0bfa88866d88b7d345258fd /src/hash.h
parent0e41e5b6c004f695013d65f71c4223e2540d1391 (diff)
downloadlibbu++-c2e3879b965d297604804f03271ac71c8c5c81f3.tar.gz
libbu++-c2e3879b965d297604804f03271ac71c8c5c81f3.tar.bz2
libbu++-c2e3879b965d297604804f03271ac71c8c5c81f3.tar.xz
libbu++-c2e3879b965d297604804f03271ac71c8c5c81f3.zip
The new taf interfaces seem to work just fine, except for saving and that loaded
TafNode structures are immutable, it all looks really good. Saving should be a snap, and the immutable part I'm not sure is bad...we'll see what happens. Also, I'm contemplating looking into a way to add "named data structure" support to the Archive at a lower level, then allow it to use a nameing system to apply names to each data structure and then output to any backend that supports naming, like taf, xml, etc.
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 }