-
Notifications
You must be signed in to change notification settings - Fork 13.3k
hash_map::OccupiedEntry::remove_entry #20601
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
Conversation
`remove_entry` is like to `remove`, but returns both key and value. Sometimes key needs to be recovered, for example, when lookup key is different from storage key.
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
Some previous discussion: http://discuss.rust-lang.org/t/maps-sets-and-the-value-of-keys/532 The overwhelming sentiment I've received is that keys are not sufficiently interesting (most collections APIs I've seen ignore them). That said, LruCache (which has been moved to collect-rs), is largely just a LinkedHashMap implementation; why doesn't what it does work for you? CC @aturon |
@gankro yes, Anyway, |
I'd be interested to see actual performance numbers, if possible. |
@gankro I doubt LruCache with My speculation: Assuming When there's no Also, note, that hash map load factor is 90%. So with |
Just going to comment that, unless I misunderstand, another use case is when the keys are basically identical, but contain owned resources. If I have a Vec in my key (I do, some times), I'd may need to recover that Vec when I remove the entry. I could just clone the key that I used, of course, so it's not the end of the world, but it is a bit silly that the HashMap is just sitting on exactly the resources I need. By "silly" I mean "involves a conversation with the allocator". :) |
Closing due to inactivity, but feel free to reopen with a rebase! |
remove_entry
is like toremove
, but returns both key and value.Sometimes key needs to be recovered, for example, when lookup key
is different from storage key.
P. S.
HashSet::remove(..)
is stable now, so it can't be changed to return contained value. What do you think about having another operation likeremove_value
. I don't need it personally, but it should probably exist for consistency and flexibility.P. P. S. I need
remove_entry
operation to implement LinkedHashSet and LinkedHashMap.