swap based on dataIndex not raw hash map index

This commit is contained in:
Brendan Hansknecht 2022-12-02 10:26:51 -08:00
parent 8a30615a20
commit ac2380f6c8
No known key found for this signature in database
GPG Key ID: 0EA784685083E75B

View File

@ -326,8 +326,9 @@ remove = \@Dict { metadata, dataIndices, data, size }, key ->
when findIndexHelper metadata dataIndices data h2Key key probe 0 is when findIndexHelper metadata dataIndices data h2Key key probe 0 is
Ok index -> Ok index ->
last = List.len data - 1 last = List.len data - 1
dataIndex = listGetUnsafe dataIndices index
if index == last then if dataIndex == last then
@Dict { @Dict {
metadata: List.set metadata index deletedSlot, metadata: List.set metadata index deletedSlot,
dataIndices, dataIndices,
@ -731,6 +732,15 @@ expect
|> remove 3 |> remove 3
keys dict == [2] keys dict == [2]
expect
list =
fromList [(T 1u8 1u8), (T 2u8 2u8), (T 3 3)]
|> remove 1
|> insert 0 0
|> remove 3
|> keys
list == [0, 2]
# Reach capacity, no rehash. # Reach capacity, no rehash.
expect expect
val = val =