Skip to content

Commit

Permalink
std: branchless bucket distance for hashmap
Browse files Browse the repository at this point in the history
  • Loading branch information
pczarn committed Sep 2, 2014
1 parent dfbd466 commit 5b0d3ad
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/libstd/collections/hashmap.rs
Expand Up @@ -802,17 +802,9 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
fn bucket_distance(&self, index_of_elem: &table::FullIndex) -> uint {
// where the hash of the element that happens to reside at
// `index_of_elem` tried to place itself first.
let first_probe_index = self.probe(&index_of_elem.hash(), 0);

let raw_index = index_of_elem.raw_index();

if first_probe_index <= raw_index {
// probe just went forward
raw_index - first_probe_index
} else {
// probe wrapped around the hashtable
raw_index + (self.table.capacity() - first_probe_index)
}
(raw_index - index_of_elem.hash() as uint) & (self.table.capacity() - 1)
}

/// Search for a pre-hashed key.
Expand Down

0 comments on commit 5b0d3ad

Please sign in to comment.