Skip to content

Commit

Permalink
fix multiply overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingSpark committed Nov 29, 2024
1 parent 79e45c4 commit f98a837
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/encoding/match_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,16 @@ impl SuffixStore {
let s2 = suffix[2] as usize;
let s3 = suffix[3] as usize;
let s4 = suffix[4] as usize;
let index = (889523592379 * (s0 << 24)) ^ (889523592379 * (s1 << 32)) ^ (889523592379 * (s2 << 40)) ^ (889523592379 * (s3 << 48)) ^ (889523592379 * (s4 << 56));

let poly = 889523592379;

let s0 = (s0 << 24).wrapping_mul(poly);
let s1 = (s1 << 32).wrapping_mul(poly);
let s2 = (s2 << 40).wrapping_mul(poly);
let s3 = (s3 << 48).wrapping_mul(poly);
let s4 = (s4 << 56).wrapping_mul(poly);

let index = s0 ^ s1 ^ s2 ^ s3 ^ s4;
let index = index >> (64 - self.len_log);
index % self.slots.len()
}
Expand Down

0 comments on commit f98a837

Please sign in to comment.