diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-04-06 14:40:44 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-04-06 14:40:44 +0000 |
commit | d37b4151d5422b164a02c3773c9ebe478d6d82da (patch) | |
tree | 09a017cb3c465ea577a8811f46c1db09a867f63f | |
parent | f7888fb3078a781ecc947ded0b064d1a901d5887 (diff) | |
download | libbu++-d37b4151d5422b164a02c3773c9ebe478d6d82da.tar.gz libbu++-d37b4151d5422b164a02c3773c9ebe478d6d82da.tar.bz2 libbu++-d37b4151d5422b164a02c3773c9ebe478d6d82da.tar.xz libbu++-d37b4151d5422b164a02c3773c9ebe478d6d82da.zip |
Also realized I had a stupid global macro in place when a template function
would work so much better. It's converted and things are much nicer now.
Diffstat (limited to '')
-rw-r--r-- | src/hash.h | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -15,8 +15,6 @@ | |||
15 | #include "bu/archivebase.h" | 15 | #include "bu/archivebase.h" |
16 | #include "bu/sharedcore.h" | 16 | #include "bu/sharedcore.h" |
17 | 17 | ||
18 | #define bitsToBytes( n ) (n/32+(n%32>0 ? 1 : 0)) | ||
19 | |||
20 | namespace Bu | 18 | namespace Bu |
21 | { | 19 | { |
22 | subExceptionDecl( HashException ) | 20 | subExceptionDecl( HashException ) |
@@ -62,6 +60,13 @@ namespace Bu | |||
62 | } | 60 | } |
63 | }; | 61 | }; |
64 | 62 | ||
63 | template<typename totype> | ||
64 | int bitsTo( int iCount ) | ||
65 | { | ||
66 | return ( (iCount/(sizeof(totype)*8)) | ||
67 | + (iCount%(sizeof(totype)*8)>0 ? 1 : 0)); | ||
68 | } | ||
69 | |||
65 | template<typename key, typename value, typename sizecalc, typename keyalloc, | 70 | template<typename key, typename value, typename sizecalc, typename keyalloc, |
66 | typename valuealloc, typename challoc> | 71 | typename valuealloc, typename challoc> |
67 | class Hash; | 72 | class Hash; |
@@ -100,7 +105,7 @@ namespace Bu | |||
100 | return; | 105 | return; |
101 | 106 | ||
102 | nCapacity = 11; | 107 | nCapacity = 11; |
103 | nKeysSize = bitsToBytes( nCapacity ); | 108 | nKeysSize = bitsTo<uint32_t>( nCapacity ); |
104 | bFilled = ca.allocate( nKeysSize ); | 109 | bFilled = ca.allocate( nKeysSize ); |
105 | bDeleted = ca.allocate( nKeysSize ); | 110 | bDeleted = ca.allocate( nKeysSize ); |
106 | clearBits(); | 111 | clearBits(); |
@@ -316,7 +321,7 @@ namespace Bu | |||
316 | 321 | ||
317 | // Calculate new sizes | 322 | // Calculate new sizes |
318 | nCapacity = nNewSize; | 323 | nCapacity = nNewSize; |
319 | nKeysSize = bitsToBytes( nCapacity ); | 324 | nKeysSize = bitsTo<uint32_t>( nCapacity ); |
320 | 325 | ||
321 | // Allocate new memory + prep | 326 | // Allocate new memory + prep |
322 | bFilled = ca.allocate( nKeysSize ); | 327 | bFilled = ca.allocate( nKeysSize ); |
@@ -1209,7 +1214,7 @@ namespace Bu | |||
1209 | pRet->nFilled = 0; | 1214 | pRet->nFilled = 0; |
1210 | pRet->nDeleted = 0; | 1215 | pRet->nDeleted = 0; |
1211 | pRet->nCapacity = src->nCapacity; | 1216 | pRet->nCapacity = src->nCapacity; |
1212 | pRet->nKeysSize = bitsToBytes( pRet->nCapacity ); | 1217 | pRet->nKeysSize = bitsTo<uint32_t>( pRet->nCapacity ); |
1213 | pRet->bFilled = pRet->ca.allocate( pRet->nKeysSize ); | 1218 | pRet->bFilled = pRet->ca.allocate( pRet->nKeysSize ); |
1214 | pRet->bDeleted = pRet->ca.allocate( pRet->nKeysSize ); | 1219 | pRet->bDeleted = pRet->ca.allocate( pRet->nKeysSize ); |
1215 | pRet->clearBits(); | 1220 | pRet->clearBits(); |