-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use displacement instead of initial bucket in HashMap code #38022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
651f4a2
to
4eddbdf
Compare
I botched the patch porting.. as always, will fix in the morning. |
51fccbb
to
092fd86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, there's just a comment that needs to be fully updated.
@@ -431,12 +431,12 @@ fn pop_internal<K, V>(starting_bucket: FullBucketMut<K, V>) -> (K, V) { | |||
} | |||
|
|||
/// Perform robin hood bucket stealing at the given `bucket`. You must | |||
/// also pass the position of that bucket's initial bucket so we don't have | |||
/// also pass the position of that bucket's displacement so we don't have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's no longer passing a “position”
@@ -522,11 +523,11 @@ impl<K, V, S> HashMap<K, V, S> | |||
|
|||
// The caller should ensure that invariants by Robin Hood Hashing hold. | |||
fn insert_hashed_ordered(&mut self, hash: SafeHash, k: K, v: V) { | |||
let raw_cap = self.raw_capacity(); | |||
let capacity = self.table.capacity(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is still the raw capacity (change is equivalent, so seems unnecessary to change).
@@ -537,8 +538,8 @@ impl<K, V, S> HashMap<K, V, S> | |||
Full(b) => b.into_bucket(), | |||
}; | |||
buckets.next(); | |||
debug_assert!(buckets.index() < limit_bucket); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an infinite loop if there is no free bucket, but that there is, is a requirement already in the caller (resize), so it seems ok.
(Note to other readers: buckets.index() keeps increasing even if the pointer it corresponds to wraps back to the first bucket.)
092fd86
to
10374a9
Compare
10374a9
to
178e29d
Compare
Thanks for the review. Commit amended with fixed/new comments. |
@bors r+ Thanks |
📌 Commit 178e29d has been approved by |
⌛ Testing commit 178e29d with merge 03bdaad... |
Use displacement instead of initial bucket in HashMap code Use displacement instead of initial bucket in HashMap code. It makes the code a bit cleaner and also saves a few instructions (handy since it'll be using some to do some sort of adaptive behavior soon).
Use displacement instead of initial bucket in HashMap code. It makes the code a bit cleaner and also saves a few instructions (handy since it'll be using some to do some sort of adaptive behavior soon).