aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/hash.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/hash.h b/src/hash.h
index 26b16c7..5c7bc78 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -42,10 +42,22 @@ namespace Bu
42 */ 42 */
43 struct __calcNextTSize_fast 43 struct __calcNextTSize_fast
44 { 44 {
45 uint32_t operator()( uint32_t nCapacity, uint32_t, uint32_t nDeleted ) const 45 uint32_t operator()( uint32_t nCapacity, uint32_t nFilled,
46 uint32_t nDeleted ) const
46 { 47 {
47 if( nDeleted >= nCapacity/2 ) 48 // This frist case will allow hashtables that are mostly deleted
49 // items to reset to small allocations
50 if( nFilled-nDeleted <= nCapacity/4 )
51 {
52 nCapacity = 11;
53 while( nCapacity < nFilled*5/4 )
54 nCapacity = nCapacity*2+1;
55 return nCapacity;
56 }
57 // This will hopefully prevent hash tables from growing needlessly
58 if( nFilled-nDeleted <= nCapacity/2 )
48 return nCapacity; 59 return nCapacity;
60 // Otherwise, just increase the capacity
49 return nCapacity*2+1; 61 return nCapacity*2+1;
50 } 62 }
51 }; 63 };