[BasicContainers] Assorted hashed container fixes and improvements#601
Open
lorentey wants to merge 8 commits intoapple:mainfrom
Open
[BasicContainers] Assorted hashed container fixes and improvements#601lorentey wants to merge 8 commits intoapple:mainfrom
lorentey wants to merge 8 commits intoapple:mainfrom
Conversation
Additionally, add some more tests that exercise various hashing outcomes.
Due to a number of cascading off-by-one errors, the maximum probe length could end up getting set lower than the actual value, _sometimes_ rendering some items unreachable. Weirdly, the issue seems to be rare enough that it somehow never triggered in any of my previous test runs.
We don’t need to calculate the probe length of the item currently occupying the new item’s ideal bucket — it cannot possibly be lower than the new item’s. This spares one hash operation during insertions that result in a hash collision.
Don’t just append new items to the end of storage — it misleads clients into assuming that the containers preserve insertion order, when they most certainly don’t do that. Instead, insert new items into the middle of storage, using an extra swap.
Member
Author
|
Cc @tfpauly, with apologies for the oversight 😅 |
0680c79 to
16e7715
Compare
…he hash table on failure
60909eb to
fda65e1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RigidSet/UniqueSet/RigidDictionary/UniqueDictionarycurrently have an implementation ofinsertthat sometimes calculates a maximum probe count that is slightly lower than the real value, and when that happensfindwill call off the search for some keys right before it would have found the match -- resulting in some of the contents being inaccessible.Implement a thorough
_checkInvariantsmethod to verify hash table layout at runtime. Use it in the existing (and some new)RigidSetunit tests to uncover corrupt results as they happen. Debug and fix their root causes.While we're here, implement a handful of important TODO items and low-hanging performance fruit:
Checklist