Skip to content

Commit 5b0d3ad

Browse files
committed
std: branchless bucket distance for hashmap
1 parent dfbd466 commit 5b0d3ad

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/libstd/collections/hashmap.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -802,17 +802,9 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
802802
fn bucket_distance(&self, index_of_elem: &table::FullIndex) -> uint {
803803
// where the hash of the element that happens to reside at
804804
// `index_of_elem` tried to place itself first.
805-
let first_probe_index = self.probe(&index_of_elem.hash(), 0);
806-
807805
let raw_index = index_of_elem.raw_index();
808806

809-
if first_probe_index <= raw_index {
810-
// probe just went forward
811-
raw_index - first_probe_index
812-
} else {
813-
// probe wrapped around the hashtable
814-
raw_index + (self.table.capacity() - first_probe_index)
815-
}
807+
(raw_index - index_of_elem.hash() as uint) & (self.table.capacity() - 1)
816808
}
817809

818810
/// Search for a pre-hashed key.

0 commit comments

Comments
 (0)