diff options
author | Thomas Herzog <thomas.herzog@mail.com> | 2018-10-12 08:42:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-12 08:42:19 +0200 |
commit | 5804efc6371fbfaec8fca6f237bd8478f2081086 (patch) | |
tree | e454ed7a95c1ea3fb421efe23afa1c144b0e9f35 | |
parent | 451e5fd0511bc2c17a66fc73a0de9a5169109517 (diff) | |
parent | 0353182e7ba925d3a162decb6f2327fec95764e2 (diff) |
Merge pull request #22929 from Windfisch/oa_hashmap_test
Fix bug and add testcase for OAHashMap losing keys
-rw-r--r-- | core/oa_hash_map.h | 4 | ||||
-rw-r--r-- | main/tests/test_oa_hash_map.cpp | 29 |
2 files changed, 31 insertions, 2 deletions
diff --git a/core/oa_hash_map.h b/core/oa_hash_map.h index 3705762d6c..9840442519 100644 --- a/core/oa_hash_map.h +++ b/core/oa_hash_map.h @@ -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; } diff --git a/main/tests/test_oa_hash_map.cpp b/main/tests/test_oa_hash_map.cpp index 26e728d3aa..deaba285cf 100644 --- a/main/tests/test_oa_hash_map.cpp +++ b/main/tests/test_oa_hash_map.cpp @@ -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 |