fix: prevent duplicate keys by reusing tombstones in map probe sequence

Previously, when inserting a key that already existed in the map but was
located after a tombstone in the probe sequence, the insertion would stop
at the first tombstone and add the key there, resulting in duplicate
entries for the same key. This fix introduces a `findEntry` function that
tracks the first encountered tombstone during probing and reuses it for
insertion only when the key is not found elsewhere in the sequence.
This commit is contained in:
Bob Nystrom
2016-06-27 14:14:52 +00:00
parent a44b210191
commit adad9f4b26
2 changed files with 96 additions and 65 deletions
+9
View File
@@ -0,0 +1,9 @@
// Regression test for #373.
var map = {}
map[2] = "two"
map[0] = "zero"
map.remove(2)
map[0] = "zero again"
map.remove(0)
System.print(map.containsKey(0)) // expect: false