Skip to content

Commit

Permalink
Factor out part of rehash_in_place
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Westerlind committed Jan 21, 2021
1 parent 7e8437f commit 0ec09ce
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,12 +758,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
// size. If both the new and old position fall within the
// same unaligned group, then there is no benefit in moving
// it and we can just continue to the next item.

let probe_seq_pos = guard.probe_seq(hash).pos;
let probe_index = |pos: usize| {
(pos.wrapping_sub(probe_seq_pos) & guard.bucket_mask) / Group::WIDTH
};
if likely(probe_index(i) == probe_index(new_i)) {
if likely(guard.is_in_same_group(i, new_i, hash)) {
guard.set_ctrl_h2(i, hash);
continue 'outer;
}
Expand Down Expand Up @@ -1286,6 +1281,14 @@ impl<A: Allocator + Clone> RawTableInner<A> {
self.items += 1;
}

#[inline]
fn is_in_same_group(&self, i: usize, new_i: usize, hash: u64) -> bool {
let probe_seq_pos = self.probe_seq(hash).pos;
let probe_index =
|pos: usize| (pos.wrapping_sub(probe_seq_pos) & self.bucket_mask) / Group::WIDTH;
probe_index(i) == probe_index(new_i)
}

/// Sets a control byte to the hash, and possibly also the replicated control byte at
/// the end of the array.
#[inline]
Expand Down

0 comments on commit 0ec09ce

Please sign in to comment.