Skip to content

Commit e946274

Browse files
fix mulhash tests
1 parent 9035db9 commit e946274

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/nthash.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,24 +225,31 @@ impl<const CANONICAL: bool, const R: u32> CharHasher for MulHasher<CANONICAL, R>
225225

226226
#[inline(always)]
227227
fn new_with_seed(k: usize, seed: Option<u32>) -> Self {
228+
let rot = (k as u32 - 1) % 32;
228229
let mul = C ^ match seed {
229230
None => 0,
230231
// don't change parity,
231232
Some(seed) => (SeedHasher::new().hash_one(seed) as u32) << 1,
232233
};
233234

234235
// Initial value of hashing `k-1` zeros.
235-
let fw_init = 0u32;
236+
let mut fw_init = 0u32;
237+
for _ in 0..k - 1 {
238+
fw_init = fw_init.rotate_left(Self::R) ^ (0 as u32).wrapping_mul(mul);
239+
}
236240

237241
// Initial value of reverse-complement-hashing `k-1` zeros.
238242
let mut rc_init = 0u32;
239243
for _ in 0..k - 1 {
240-
rc_init = rc_init.rotate_right(Self::R) ^ (complement_base(0) as u32).wrapping_mul(mul);
244+
rc_init = rc_init.rotate_right(Self::R)
245+
^ (complement_base(0) as u32)
246+
.wrapping_mul(mul)
247+
.rotate_left(rot * R);
241248
}
242249

243250
Self {
244251
k,
245-
rot: (k as u32 - 1) % 32,
252+
rot,
246253
mul,
247254
fw_init,
248255
rc_init,

0 commit comments

Comments
 (0)