diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-06-07 04:55:29 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-06-07 04:55:29 +0000 |
commit | c2e3879b965d297604804f03271ac71c8c5c81f3 (patch) | |
tree | e3abe738a7aca61fc0bfa88866d88b7d345258fd /src | |
parent | 0e41e5b6c004f695013d65f71c4223e2540d1391 (diff) | |
download | libbu++-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 '')
-rw-r--r-- | src/hash.h | 53 | ||||
-rw-r--r-- | src/tafnode.cpp | 24 | ||||
-rw-r--r-- | src/tafnode.h | 8 | ||||
-rw-r--r-- | src/tests/taf.cpp | 9 |
4 files changed, 77 insertions, 17 deletions
@@ -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 | } |
diff --git a/src/tafnode.cpp b/src/tafnode.cpp index ed8adc0..3060606 100644 --- a/src/tafnode.cpp +++ b/src/tafnode.cpp | |||
@@ -6,13 +6,13 @@ Bu::TafNode::TafNode() | |||
6 | 6 | ||
7 | Bu::TafNode::~TafNode() | 7 | Bu::TafNode::~TafNode() |
8 | { | 8 | { |
9 | printf("Entering Bu::TafNode::~TafNode() \"%s\"\n", sName.getStr() ); | 9 | //printf("Entering Bu::TafNode::~TafNode() \"%s\"\n", sName.getStr() ); |
10 | for( NodeHash::iterator i = hChildren.begin(); i != hChildren.end(); i++ ) | 10 | for( NodeHash::iterator i = hChildren.begin(); i != hChildren.end(); i++ ) |
11 | { | 11 | { |
12 | NodeList &l = i.getValue(); | 12 | NodeList &l = i.getValue(); |
13 | for( NodeList::iterator k = l.begin(); k != l.end(); k++ ) | 13 | for( NodeList::iterator k = l.begin(); k != l.end(); k++ ) |
14 | { | 14 | { |
15 | printf("deleting: [%08X] %s\n", *k, "" );//(*k)->getName().getStr() ); | 15 | //printf("deleting: [%08X] %s\n", *k, "" );//(*k)->getName().getStr() ); |
16 | delete (*k); | 16 | delete (*k); |
17 | } | 17 | } |
18 | } | 18 | } |
@@ -35,27 +35,37 @@ void Bu::TafNode::addChild( TafNode *pNode ) | |||
35 | hChildren.insert( pNode->getName(), NodeList() ); | 35 | hChildren.insert( pNode->getName(), NodeList() ); |
36 | } | 36 | } |
37 | 37 | ||
38 | printf("Appending \"%s\"\n", pNode->getName().getStr() ); | 38 | //printf("Appending \"%s\"\n", pNode->getName().getStr() ); |
39 | hChildren.get( pNode->getName() ).append( pNode ); | 39 | hChildren.get( pNode->getName() ).append( pNode ); |
40 | printf("[%08X]\n", hChildren.get( pNode->getName() ).last() ); | 40 | //printf("[%08X]\n", hChildren.get( pNode->getName() ).last() ); |
41 | } | 41 | } |
42 | 42 | ||
43 | const Bu::TafNode::PropList &Bu::TafNode::getProperty( const Bu::FString &sName ) | 43 | const Bu::TafNode::PropList &Bu::TafNode::getProperties( const Bu::FString &sName ) const |
44 | { | 44 | { |
45 | return hProp.get( sName ); | 45 | return hProp.get( sName ); |
46 | } | 46 | } |
47 | 47 | ||
48 | const Bu::TafNode::NodeList &Bu::TafNode::getNode( const Bu::FString &sName ) | 48 | const Bu::TafNode::NodeList &Bu::TafNode::getNodes( const Bu::FString &sName ) const |
49 | { | 49 | { |
50 | return hChildren.get( sName ); | 50 | return hChildren.get( sName ); |
51 | } | 51 | } |
52 | 52 | ||
53 | const Bu::FString &Bu::TafNode::getProperty( const Bu::FString &sName ) const | ||
54 | { | ||
55 | return getProperties( sName ).first(); | ||
56 | } | ||
57 | |||
58 | const Bu::TafNode *Bu::TafNode::getNode( const Bu::FString &sName ) const | ||
59 | { | ||
60 | return getNodes( sName ).first(); | ||
61 | } | ||
62 | |||
53 | void Bu::TafNode::setName( const Bu::FString &sName ) | 63 | void Bu::TafNode::setName( const Bu::FString &sName ) |
54 | { | 64 | { |
55 | this->sName = sName; | 65 | this->sName = sName; |
56 | } | 66 | } |
57 | 67 | ||
58 | const Bu::FString &Bu::TafNode::getName() | 68 | const Bu::FString &Bu::TafNode::getName() const |
59 | { | 69 | { |
60 | return sName; | 70 | return sName; |
61 | } | 71 | } |
diff --git a/src/tafnode.h b/src/tafnode.h index a570d2d..10232d2 100644 --- a/src/tafnode.h +++ b/src/tafnode.h | |||
@@ -24,11 +24,13 @@ namespace Bu | |||
24 | virtual ~TafNode(); | 24 | virtual ~TafNode(); |
25 | 25 | ||
26 | void setName( const Bu::FString &sName ); | 26 | void setName( const Bu::FString &sName ); |
27 | const Bu::FString &getName(); | 27 | const Bu::FString &getName() const; |
28 | 28 | ||
29 | void setProperty( Bu::FString sName, Bu::FString sValue ); | 29 | void setProperty( Bu::FString sName, Bu::FString sValue ); |
30 | const PropList &getProperty( const Bu::FString &sName ); | 30 | const Bu::FString &getProperty( const Bu::FString &sName ) const; |
31 | const NodeList &getNode( const Bu::FString &sName ); | 31 | const TafNode *getNode( const Bu::FString &sName ) const; |
32 | const PropList &getProperties( const Bu::FString &sName ) const; | ||
33 | const NodeList &getNodes( const Bu::FString &sName ) const; | ||
32 | void addChild( TafNode *pNode ); | 34 | void addChild( TafNode *pNode ); |
33 | 35 | ||
34 | private: | 36 | private: |
diff --git a/src/tests/taf.cpp b/src/tests/taf.cpp index f7af2b2..e7bad52 100644 --- a/src/tests/taf.cpp +++ b/src/tests/taf.cpp | |||
@@ -8,12 +8,9 @@ int main() | |||
8 | 8 | ||
9 | Bu::TafNode *pNode = tr.getNode(); | 9 | Bu::TafNode *pNode = tr.getNode(); |
10 | 10 | ||
11 | const Bu::TafNode::NodeList &l = pNode->getNode("stats"); | 11 | const Bu::TafNode *pStats = pNode->getNode("stats"); |
12 | for( Bu::TafNode::NodeList::const_iterator i = l.begin(); | 12 | printf("%s\n", pStats->getName().getStr() ); |
13 | i != l.end(); i++ ) | 13 | printf(" str = %s\n", pStats->getProperty("str").getStr() ); |
14 | { | ||
15 | printf("%s\n", (*i)->getName().getStr() ); | ||
16 | } | ||
17 | 14 | ||
18 | delete pNode; | 15 | delete pNode; |
19 | } | 16 | } |