From 01756ca4a340fd9dc56b92c9a67b6ca73157e9f9 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 27 Jan 2007 22:48:33 +0000 Subject: New feature in Hash, a copy constructor, you can now put a hash into other templatized containers. --- src/hash.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/hash.h') diff --git a/src/hash.h b/src/hash.h index 1ae68b8..c65b20d 100644 --- a/src/hash.h +++ b/src/hash.h @@ -141,6 +141,34 @@ public: aValues = va.allocate( nCapacity ); } + Hash( const Hash &src ) : + nCapacity( src.nCapacity ), + nFilled( 0 ), + nDeleted( 0 ), + bFilled( NULL ), + bDeleted( NULL ), + aKeys( NULL ), + aValues( NULL ), + aHashCodes( NULL ) + { + nKeysSize = bitsToBytes( nCapacity ); + bFilled = ca.allocate( nKeysSize ); + bDeleted = ca.allocate( nKeysSize ); + clearBits(); + + aHashCodes = ca.allocate( nCapacity ); + aKeys = ka.allocate( nCapacity ); + aValues = va.allocate( nCapacity ); + + for( uint32_t j = 0; j < nCapacity; j++ ) + { + if( src.isFilled( j ) ) + { + insert( src.aKeys[j], src.aValues[j] ); + } + } + } + virtual ~Hash() { for( uint32_t j = 0; j < nCapacity; j++ ) @@ -502,7 +530,7 @@ protected: ca.deallocate( aOldHashCodes, nOldCapacity ); } - virtual bool isFilled( uint32_t loc ) + virtual bool isFilled( uint32_t loc ) const { return (bFilled[loc/32]&(1<<(loc%32)))!=0; } -- cgit v1.2.3