diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-04-07 17:44:57 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-04-07 17:44:57 +0000 |
commit | 943cf16f5661357086532b2241e6f85bfe43565a (patch) | |
tree | 6ef615680835ea0415becf62387168a31cb36b32 /src | |
parent | 6cdf5615a2729df486def3fae2e6f548a34fb83b (diff) | |
download | libbu++-943cf16f5661357086532b2241e6f85bfe43565a.tar.gz libbu++-943cf16f5661357086532b2241e6f85bfe43565a.tar.bz2 libbu++-943cf16f5661357086532b2241e6f85bfe43565a.tar.xz libbu++-943cf16f5661357086532b2241e6f85bfe43565a.zip |
Corrected a long standing yet seldom witnessed hash bug. It was triggered when
a hashtable was filled, then some items were removed, then enough items were
added to trigger a rehash.
Diffstat (limited to 'src')
-rw-r--r-- | src/hash.h | 3 | ||||
-rw-r--r-- | src/tests/hash2.cpp | 28 |
2 files changed, 30 insertions, 1 deletions
@@ -1115,7 +1115,8 @@ namespace Bu | |||
1115 | // Delete all of the old data | 1115 | // Delete all of the old data |
1116 | for( uint32_t j = 0; j < nOldCapacity; j++ ) | 1116 | for( uint32_t j = 0; j < nOldCapacity; j++ ) |
1117 | { | 1117 | { |
1118 | if( (bOldFilled[j/32]&(1<<(j%32)))!=0 ) | 1118 | if( (bOldFilled[j/32]&(1<<(j%32)))!=0 && |
1119 | (bOldDeleted[j/32]&(1<<(j%32)))==0 ) | ||
1119 | { | 1120 | { |
1120 | va.destroy( &aOldValues[j] ); | 1121 | va.destroy( &aOldValues[j] ); |
1121 | ka.destroy( &aOldKeys[j] ); | 1122 | ka.destroy( &aOldKeys[j] ); |
diff --git a/src/tests/hash2.cpp b/src/tests/hash2.cpp new file mode 100644 index 0000000..24c9d8c --- /dev/null +++ b/src/tests/hash2.cpp | |||
@@ -0,0 +1,28 @@ | |||
1 | #include <bu/fstring.h> | ||
2 | #include <bu/hash.h> | ||
3 | |||
4 | int main() | ||
5 | { | ||
6 | Bu::Hash<Bu::FString, int> hCmd; | ||
7 | |||
8 | hCmd.insert("help", 5 ); | ||
9 | hCmd.insert("exit", 5 ); | ||
10 | hCmd.insert("getkey", 5 ); | ||
11 | hCmd.insert("setcrypt", 5 ); | ||
12 | hCmd.insert("user", 5 ); | ||
13 | hCmd.insert("pass", 5 ); | ||
14 | hCmd.erase("getkey"); | ||
15 | hCmd.erase("setcrypt"); | ||
16 | hCmd.insert("user", 5 ); | ||
17 | hCmd.insert("pass", 5 ); | ||
18 | hCmd.erase("pass"); | ||
19 | hCmd.erase("user"); | ||
20 | hCmd.insert("acl", 5 ); | ||
21 | hCmd.insert("owner", 5 ); | ||
22 | hCmd.insert("operator", 5 ); | ||
23 | hCmd.insert("admin", 5 ); | ||
24 | hCmd.insert("monitor", 5 ); | ||
25 | hCmd.insert("shutdown", 5 ); | ||
26 | |||
27 | return 0; | ||
28 | } | ||