Merge pull request #22929 from Windfisch/oa_hashmap_test

Fix bug and add testcase for OAHashMap losing keys
This commit is contained in:
Thomas Herzog 2018-10-12 08:42:19 +02:00 committed by GitHub
commit 5804efc637
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View file

@ -125,7 +125,7 @@ private:
while (42) {
if (hashes[pos] == EMPTY_HASH) {
_construct(pos, hash, p_key, p_value);
_construct(pos, hash, key, value);
return;
}
@ -136,7 +136,7 @@ private:
if (hashes[pos] & DELETED_HASH_BIT) {
// we found a place where we can fit in!
_construct(pos, hash, p_key, p_value);
_construct(pos, hash, key, value);
return;
}

View file

@ -92,6 +92,35 @@ MainLoop *test() {
}
}
// stress test / test for issue #22928
{
OAHashMap<int, int> map;
int dummy;
const int N = 1000;
uint32_t *keys = new uint32_t[N];
Math::seed(0);
// insert a couple of random keys (with a dummy value, which is ignored)
for (int i = 0; i < N; i++) {
keys[i] = Math::rand();
map.set(keys[i], dummy);
if (!map.lookup(keys[i], dummy))
OS::get_singleton()->print("could not find 0x%X despite it was just inserted!\n", unsigned(keys[i]));
}
// check whether the keys are still present
for (int i = 0; i < N; i++) {
if (!map.lookup(keys[i], dummy)) {
OS::get_singleton()->print("could not find 0x%X despite it has been inserted previously! (not checking the other keys, breaking...)\n", unsigned(keys[i]));
break;
}
}
delete[] keys;
}
return NULL;
}
} // namespace TestOAHashMap