Skip to content

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

Merged
merged 1 commit into from
Nov 28, 2016

Conversation

arthurprs
Copy link
Contributor

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).

@rust-highfive
Copy link
Contributor

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@arthurprs
Copy link
Contributor Author

arthurprs commented Nov 27, 2016

I botched the patch porting.. as always, will fix in the morning.

@arthurprs arthurprs force-pushed the micro-opt-hm branch 3 times, most recently from 51fccbb to 092fd86 Compare November 27, 2016 18:05
Copy link
Member

@bluss bluss left a 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
Copy link
Member

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();
Copy link
Member

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);
Copy link
Member

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.)

@arthurprs
Copy link
Contributor Author

arthurprs commented Nov 27, 2016

Thanks for the review. Commit amended with fixed/new comments.

@arthurprs arthurprs closed this Nov 27, 2016
@arthurprs arthurprs reopened this Nov 27, 2016
@bluss
Copy link
Member

bluss commented Nov 27, 2016

@bors r+

Thanks

@bors
Copy link
Collaborator

bors commented Nov 27, 2016

📌 Commit 178e29d has been approved by bluss

@bors
Copy link
Collaborator

bors commented Nov 27, 2016

⌛ Testing commit 178e29d with merge 03bdaad...

bors added a commit that referenced this pull request Nov 27, 2016
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).
@bors bors merged commit 178e29d into rust-lang:master Nov 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants