From a4a2856cb7fd68837d392948dfe60e5863a0de18 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Wed, 10 May 2023 19:20:49 +0100 Subject: [PATCH] Stop searching if we've already overshot where it could be --- agb-hashmap/src/node_storage.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/agb-hashmap/src/node_storage.rs b/agb-hashmap/src/node_storage.rs index 46e14d3..e748367 100644 --- a/agb-hashmap/src/node_storage.rs +++ b/agb-hashmap/src/node_storage.rs @@ -142,6 +142,13 @@ impl NodeStorage { let location = (hash + distance_to_initial_bucket).fast_mod(self.backing_vec_size()); let node = &self.nodes[location]; + + // if we've seen a node which is further from home than what we'd expect to find, then + // our node cannot exist because it would've been inserted here. + if node.distance() < distance_to_initial_bucket { + return None; + } + let node_key_ref = node.key_ref()?; if node_key_ref.borrow() == key {