Skip to content

Conversation

@clarfonthey
Copy link
Contributor

The primary addition here is OccupiedEntry::replace_key, which allows replacing the key in the map. Since this is an uncommon operation, I decided to make it unsafe and not check for the equivalence of the key, but that can potentially be changed.

The other change that is made here is VacantEntryRef::{insert_with_key,insert_entry_with_key} now have unchecked versions which do not check the equivalence of the key, to ensure the same behaviour with the replace function never panicking.

Unfortunately, an UnsafeCell is required to truly make this API work without accessing internals, but it shouldn't ultimately matter, I think. The result is the find_or_find_insert_index method of HashMap is no longer exported, and instead the entry API is used by HashSet. Now, the only remaining raw table API for HashSet is RawExtractIf, to be fixed later.

Comment on lines +3800 to +3801
/// assert!(std::ptr::eq(replaced, old_key));
/// assert!(std::ptr::eq(*entry.key(), new_key));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed like the best way to ensure the key was truly "replaced" instead of having a custom struct with a custom PartialEq implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant