third_party_rust_hashbrown/benches
Stiopa Koltsov 8d6c278366 insert_unique_unchecked operation
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](https://github.com/bluss/indexmap/pull/200)
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).
2021-09-12 19:40:29 +01:00
..
bench.rs Fix a clippy warning in benches 2021-08-13 23:34:01 +02:00
insert_unique_unchecked.rs insert_unique_unchecked operation 2021-09-12 19:40:29 +01:00