aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-01-27 22:48:33 +0000
committerMike Buland <eichlan@xagasoft.com>2007-01-27 22:48:33 +0000
commit01756ca4a340fd9dc56b92c9a67b6ca73157e9f9 (patch)
treeb9f0fb96858247d72588e137f1e1a0a11c8683e1 /src
parent603f45fbe9c3e0ac511425a13bbb19b87495bb4e (diff)
downloadlibbu++-01756ca4a340fd9dc56b92c9a67b6ca73157e9f9.tar.gz
libbu++-01756ca4a340fd9dc56b92c9a67b6ca73157e9f9.tar.bz2
libbu++-01756ca4a340fd9dc56b92c9a67b6ca73157e9f9.tar.xz
libbu++-01756ca4a340fd9dc56b92c9a67b6ca73157e9f9.zip
New feature in Hash, a copy constructor, you can now put a hash into other
templatized containers.
Diffstat (limited to '')
-rw-r--r--src/hash.h30
1 files changed, 29 insertions, 1 deletions
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:
141 aValues = va.allocate( nCapacity ); 141 aValues = va.allocate( nCapacity );
142 } 142 }
143 143
144 Hash( const Hash &src ) :
145 nCapacity( src.nCapacity ),
146 nFilled( 0 ),
147 nDeleted( 0 ),
148 bFilled( NULL ),
149 bDeleted( NULL ),
150 aKeys( NULL ),
151 aValues( NULL ),
152 aHashCodes( NULL )
153 {
154 nKeysSize = bitsToBytes( nCapacity );
155 bFilled = ca.allocate( nKeysSize );
156 bDeleted = ca.allocate( nKeysSize );
157 clearBits();
158
159 aHashCodes = ca.allocate( nCapacity );
160 aKeys = ka.allocate( nCapacity );
161 aValues = va.allocate( nCapacity );
162
163 for( uint32_t j = 0; j < nCapacity; j++ )
164 {
165 if( src.isFilled( j ) )
166 {
167 insert( src.aKeys[j], src.aValues[j] );
168 }
169 }
170 }
171
144 virtual ~Hash() 172 virtual ~Hash()
145 { 173 {
146 for( uint32_t j = 0; j < nCapacity; j++ ) 174 for( uint32_t j = 0; j < nCapacity; j++ )
@@ -502,7 +530,7 @@ protected:
502 ca.deallocate( aOldHashCodes, nOldCapacity ); 530 ca.deallocate( aOldHashCodes, nOldCapacity );
503 } 531 }
504 532
505 virtual bool isFilled( uint32_t loc ) 533 virtual bool isFilled( uint32_t loc ) const
506 { 534 {
507 return (bFilled[loc/32]&(1<<(loc%32)))!=0; 535 return (bFilled[loc/32]&(1<<(loc%32)))!=0;
508 } 536 }