

insert_unique_unchecked operation by stepancheg · Pull Request #293 · rust-lang/...
source link: https://github.com/rust-lang/hashbrown/pull/293
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Sometimes a map is constructed when it is known that all keys are
unique (e. e. if keys are coming from another map or from a
sorted/deduplicated iterator). In this case we can make insertion
faster by skipping a check that a key already exists in the map.
insert_unique_unchecked
is guaranteed to be memory-safe, but does
not guarantee anything beyond that: if inserted key is not unique,HashMap
can panic, loop forever, return incorrect entry etc.
Added simple benchmark. insert_unique_unchecked
is about 30%
faster than insert
. Your mileage may vary of course.
Similar PR was
added to indexmap
crate
and they asked to discuss the name of the operation with hashbrown
crate owners to come to the same naming convention (if hashbrown
is willing to have the same operation).
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK