Skip to content

Commit 0407e05

Browse files
zakcutnermarmeladema
authored andcommitted
Use wrapping sum rolling hash for Rabin-Karp implementation
1 parent 42dee6c commit 0407e05

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/x86/avx2/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::arch::x86::*;
1111
use std::arch::x86_64::*;
1212
use std::mem;
1313

14-
/// Rolling hash for the simple Rabin-Karp implementation. As a hashing function, the XOR of all the
14+
/// Rolling hash for the simple Rabin-Karp implementation. As a hashing function, the sum of all the
1515
/// bytes is computed.
1616
#[derive(Clone, Copy, Default, PartialEq)]
1717
struct ScalarHash(usize);
@@ -29,12 +29,12 @@ impl From<&[u8]> for ScalarHash {
2929
impl ScalarHash {
3030
#[inline]
3131
fn push(&mut self, b: u8) {
32-
self.0 ^= usize::from(b);
32+
self.0 = self.0.wrapping_add(b.into());
3333
}
3434

3535
#[inline]
3636
fn pop(&mut self, b: u8) {
37-
self.0 ^= usize::from(b);
37+
self.0 = self.0.wrapping_sub(b.into());
3838
}
3939
}
4040

0 commit comments

Comments
 (0)