-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: faster, linear HashMap.alter and modify #6573
Conversation
Mathlib CI status (docs):
|
@kim-em There was, in fact, a linearity problem. Here is the code for @[inline] def alter [LawfulBEq α] (m : DHashMap α β) (a : α) (f : Option (β a) → Option (β a)) : DHashMap α β :=
match m.get? a with
| none =>
match f none with
| none => m
| some b => m.insert a b
| some b =>
match f (some b) with
| none => m.erase a
| some b => m.erase a |>.insert a b In the very bottom branch, we verified using the IR and using benchmarks that the compiler decided to first run |
(Update: I didn't see Markus' comment before writing this)
Indeed, it turned out that
In my benchmarks, |
Awesome! Glad I asked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for the final few remarks, feel free to merge after fixing.
This PR replaces the existing implementations of
(D)HashMap.alter
and(D)HashMap.modify
with primitive, more efficient ones and in particular provides proofs that they yield well-formed hash maps (WF
typeclass).