From dfd5f8696787d18ae688b662040289f84b667fdd Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 24 Jan 2009 00:59:12 +0000 Subject: Added some append and prepend functions and operators to Bu::List, now you can append one list to another and the like. Also, wow, I found a bug that's been around for ages, I guess we don't copy hash tables often. The interesting thing is that it actually worked, it copied but it would include any data that had been deleted in the old hash table but not reclaimed yet and insert it as new data. Usually the key had been completely destroyed (like with a string) so it came out as keyed to blank string. So in cases like that, all deleted keys would collapse into one deleted key in the new hash table. --- src/hash.h | 15 +++++++-------- src/list.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/hash.h b/src/hash.h index 8c58645..8856860 100644 --- a/src/hash.h +++ b/src/hash.h @@ -268,7 +268,7 @@ namespace Bu for( uint32_t j = 0; j < src.nCapacity; j++ ) { - if( src.isFilled( j ) ) + if( src.isFilled( j ) && !src.isDeleted( j ) ) { insert( src.aKeys[j], src.aValues[j] ); } @@ -283,12 +283,11 @@ namespace Bu { for( uint32_t j = 0; j < nCapacity; j++ ) { - if( isFilled( j ) ) - if( !isDeleted( j ) ) - { - va.destroy( &aValues[j] ); - ka.destroy( &aKeys[j] ); - } + if( isFilled( j ) && !isDeleted( j ) ) + { + va.destroy( &aValues[j] ); + ka.destroy( &aKeys[j] ); + } } va.deallocate( aValues, nCapacity ); ka.deallocate( aKeys, nCapacity ); @@ -310,7 +309,7 @@ namespace Bu for( uint32_t j = 0; j < src.nCapacity; j++ ) { - if( src.isFilled( j ) ) + if( src.isFilled( j ) && !src.isDeleted( j ) ) { insert( src.aKeys[j], src.aValues[j] ); } diff --git a/src/list.h b/src/list.h index 8c5e94e..d16e606 100644 --- a/src/list.h +++ b/src/list.h @@ -82,6 +82,18 @@ namespace Bu return *this; } + MyType &operator+=( const value &v ) + { + append( v ); + return *this; + } + + MyType &operator+=( const MyType &src ) + { + append( src ); + return *this; + } + /** * Clear the data from the list. */ @@ -142,6 +154,15 @@ namespace Bu } } + void append( const MyType &rSrc ) + { + for( typename MyType::const_iterator i = rSrc.begin(); + i != rSrc.end(); i++ ) + { + append( *i ); + } + } + /** * Prepend a value to the list. *@param v (const value_type &) The value to prepend. @@ -167,6 +188,19 @@ namespace Bu } } + /** + * Prepend another list to the front of this one. This will prepend + * the rSrc list in reverse order...I may fix that later. + */ + void prepend( const MyType &rSrc ) + { + for( typename MyType::const_iterator i = rSrc.begin(); + i != rSrc.end(); i++ ) + { + prepend( *i ); + } + } + /** * Insert a new item in sort order by searching for the first item that * is larger and inserting this before it, or at the end if none are -- cgit v1.2.3