diff options
| -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(); | 
