Compare commits

...

1 Commits

Author SHA1 Message Date
Henrik Böving
321f8c0be9 perf: fix linearity in (HashSet|HashMap).erase 2024-04-12 10:16:51 +02:00
2 changed files with 8 additions and 4 deletions

View File

@@ -137,8 +137,10 @@ def erase [BEq α] [Hashable α] (m : HashMapImp α β) (a : α) : HashMapImp α
| size, buckets =>
let i, h := mkIdx (hash a) buckets.property
let bkt := buckets.val[i]
if bkt.contains a then size - 1, buckets.update i (bkt.erase a) h
else m
if bkt.contains a then
size - 1, buckets.update i (bkt.erase a) h
else
size, buckets
inductive WellFormed [BEq α] [Hashable α] : HashMapImp α β Prop where
| mkWff : n, WellFormed (mkHashMapImp n)

View File

@@ -112,8 +112,10 @@ def erase [BEq α] [Hashable α] (m : HashSetImp α) (a : α) : HashSetImp α :=
| size, buckets =>
let i, h := mkIdx (hash a) buckets.property
let bkt := buckets.val[i]
if bkt.contains a then size - 1, buckets.update i (bkt.erase a) h
else m
if bkt.contains a then
size - 1, buckets.update i (bkt.erase a) h
else
size, buckets
inductive WellFormed [BEq α] [Hashable α] : HashSetImp α Prop where
| mkWff : n, WellFormed (mkHashSetImp n)