Fix `HashSet::get_or_insert_with`
Fix #399. Tried to do it without additional overhead. Unless there are additional comparisons.
Should an unsafe _unchecked function also be added? Hashing and comparing the insert_value should be unnecessary if this function is used properly.
Should an
unsafe _uncheckedfunction also be added? Hashing and comparing theinsert_valueshould be unnecessary if this function is used properly.
Well, strictly speaking, rehashing was present in the old version of the code. Only two comparisons and a panic were added here. Let's see what @Amanieu says :-).
In theory, as I understand it, there is nothing that violates memory or causes UB in the fact that there are two or more identical elements in a Hashmap or HashSet. It just increases the collision, the elements after the first one will be lost and will only show up when iterating. The documentation for HashMap::insert_unique_unchecked scares people a little. Anyway, I can't even imagine when insert_unique_unchecked «operation may panic, loop forever, or any following operation with the map may panic, loop forever or return arbitrary result».
:umbrella: The latest upstream changes (presumably #390) made this pull request unmergeable. Please resolve the merge conflicts.
:umbrella: The latest upstream changes (presumably #533) made this pull request unmergeable. Please resolve the merge conflicts.