From 943cf16f5661357086532b2241e6f85bfe43565a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 7 Apr 2010 17:44:57 +0000 Subject: 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. --- src/hash.h | 3 ++- src/tests/hash2.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/tests/hash2.cpp diff --git a/src/hash.h b/src/hash.h index cb3001a..1cb539b 100644 --- a/src/hash.h +++ b/src/hash.h @@ -1115,7 +1115,8 @@ namespace Bu // Delete all of the old data for( uint32_t j = 0; j < nOldCapacity; j++ ) { - if( (bOldFilled[j/32]&(1<<(j%32)))!=0 ) + if( (bOldFilled[j/32]&(1<<(j%32)))!=0 && + (bOldDeleted[j/32]&(1<<(j%32)))==0 ) { va.destroy( &aOldValues[j] ); 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 @@ +#include +#include + +int main() +{ + Bu::Hash hCmd; + + hCmd.insert("help", 5 ); + hCmd.insert("exit", 5 ); + hCmd.insert("getkey", 5 ); + hCmd.insert("setcrypt", 5 ); + hCmd.insert("user", 5 ); + hCmd.insert("pass", 5 ); + hCmd.erase("getkey"); + hCmd.erase("setcrypt"); + hCmd.insert("user", 5 ); + hCmd.insert("pass", 5 ); + hCmd.erase("pass"); + hCmd.erase("user"); + hCmd.insert("acl", 5 ); + hCmd.insert("owner", 5 ); + hCmd.insert("operator", 5 ); + hCmd.insert("admin", 5 ); + hCmd.insert("monitor", 5 ); + hCmd.insert("shutdown", 5 ); + + return 0; +} -- cgit v1.2.3