From 37dfdbdc97fceface901c6bce7a34342989576f1 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Thu, 1 Dec 2016 13:51:49 +0100 Subject: [PATCH] VM: Remove unused (and incomplete) HashMap::Remove() function R=vegorov@google.com Review URL: https://codereview.chromium.org/2542103002 . --- runtime/bin/hashmap_test.cc | 43 ------------------------------------- runtime/platform/hashmap.cc | 17 --------------- runtime/platform/hashmap.h | 17 --------------- 3 files changed, 77 deletions(-) diff --git a/runtime/bin/hashmap_test.cc b/runtime/bin/hashmap_test.cc index 0a4ee31ed10..bad384b79a3 100644 --- a/runtime/bin/hashmap_test.cc +++ b/runtime/bin/hashmap_test.cc @@ -180,47 +180,4 @@ UNIT_TEST_CASE(HashMap_Basic) { TestSet(CollisionHash4, 50); } - -UNIT_TEST_CASE(HashMap_RemoveDuringIteration) { - class Utils { - public: - static bool MatchFun(void* key1, void* key2) { return key1 == key2; } - static void* Key(intptr_t i) { return reinterpret_cast(i); } - static void* Value(intptr_t i) { return reinterpret_cast(i); } - static uint32_t HashCode(intptr_t key) { return 1; } - }; - - HashMap map(Utils::MatchFun, 8); - - // Add 6 (1, 1), ..., (6, 60) entries to the map all with a hashcode of 1 - // (i.e. have all keys have collinding hashcode). - // - // This causes the probing position in the hashmap to be 1 and open-addressing - // with linear probing will fill in the slots towards the right - // (i.e. from 1..6). - for (intptr_t i = 1; i <= 6 /* avoid rehash at 7 */; i++) { - HashMap::Entry* entry = map.Lookup(Utils::Key(i), Utils::HashCode(i), true); - entry->value = Utils::Value(10 * i); - } - - // Now we iterate over all elements and delete the current element. Since all - // our entries have a colliding hashcode of 1, each deletion will cause all - // following elements to be left-rotated by 1. - intptr_t i = 0; - HashMap::Entry* current = map.Start(); - while (current != NULL) { - i++; - EXPECT_EQ(Utils::Key(i), current->key); - EXPECT_EQ(Utils::Value(10 * i), current->value); - - // Every 2nd element we keep to hit the left-rotation case only sometimes. - if (i % 2 == 0) { - current = map.Remove(current); - } else { - current = map.Next(current); - } - } - EXPECT_EQ(6, i); -} - } // namespace dart diff --git a/runtime/platform/hashmap.cc b/runtime/platform/hashmap.cc index 4d4b4774dd3..4a18cb211ca 100644 --- a/runtime/platform/hashmap.cc +++ b/runtime/platform/hashmap.cc @@ -110,23 +110,6 @@ void HashMap::Remove(void* key, uint32_t hash) { } -HashMap::Entry* HashMap::Remove(Entry* entry) { - Remove(entry->key, entry->hash); - - // A key can only exist once in the map and we just removed `key`. This means - // that either a left-rotation has happened (in which case `entry` points - // already to the next element (in terms of iteration order)) or alternatively - // we can use the normal `Next()` call to move in iteration order. - if (entry->key != NULL) { - // A left-rotation happened. `entry` points already to the next element in - // iteration order. - return entry; - } else { - return Next(entry); - } -} - - void HashMap::Clear(ClearFun clear) { // Mark all entries as empty. const Entry* end = map_end(); diff --git a/runtime/platform/hashmap.h b/runtime/platform/hashmap.h index 240e94d1a0f..be8278e909d 100644 --- a/runtime/platform/hashmap.h +++ b/runtime/platform/hashmap.h @@ -66,23 +66,6 @@ class HashMap { // otherwise the iteration might step over elements! void Remove(void* key, uint32_t hash); - // Removes the entry and returns the next entry (in iteration order) after - // this one. - // - // Usage instructions for removing elements during iteration: - // - // HashMap::Entry* current = map.Start(); - // while (current != NULL) { - // ... - // if (condition) { - // current = map.Remove(current); - // } else { - // current = map.Next(current); - // } - // } - // - Entry* Remove(Entry* entry); - // Empties the hash map (occupancy() == 0), and calls the function 'clear' on // each of the values if given. void Clear(ClearFun clear = NULL);