Skip to content

Commit 6763f88

Browse files
committed
Cleanup hashmod function
1 parent 63d3f0c commit 6763f88

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ fn hash_with_seed<T: Hash + ?Sized>(iter: u64, v: &T) -> u64 {
6464
state.finish()
6565
}
6666

67-
#[inline]
68-
fn hash_with_seed32<T: Hash + ?Sized>(iter: u64, v: &T) -> u32 {
69-
fold(hash_with_seed(iter, v))
70-
}
71-
7267
#[inline]
7368
fn fastmod(hash: u32, n: u32) -> u64 {
7469
((hash as u64) * (n as u64)) >> 32
@@ -78,11 +73,10 @@ fn fastmod(hash: u32, n: u32) -> u64 {
7873
fn hashmod<T: Hash + ?Sized>(iter: u64, v: &T, n: u64) -> u64 {
7974
// when n < 2^32, use the fast alternative to modulo described here:
8075
// https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
76+
let h = hash_with_seed(iter, v);
8177
if n < (1 << 32) {
82-
let h = hash_with_seed32(iter, v);
83-
fastmod(h, n as u32) as u64
78+
fastmod(fold(h), n as u32) as u64
8479
} else {
85-
let h = hash_with_seed(iter, v);
8680
h % (n as u64)
8781
}
8882
}

0 commit comments

Comments
 (0)