Expand description
Rolling (Rabin-Karp-style) hash for strings and byte slices.
Provides two flavours:
-
RollingHash— single-modulus rolling hash over&[u8]. The current hash value is maintained incrementally as the window slides. Useful when you need a fingerprint that updates inO(1)per shift. -
DoubleRollingHash— same idea, with two different moduli for very low collision rates; pairs of hashes can be compared for equality.
Both flavours precompute the base-power table for substrings up to some
max_len. To compare hashes of arbitrary substrings of a long string,
use compute_hash (single) or build a DoubleRollingHash and
query substrings using hash_range(lo, hi) / combine(lo1, hi1, lo2, hi2).
Structs§
- Double
Rolling Hash - Two-modulus rolling hash with combine/equal-friendly semantics.
- Rolling
Hash - Single-modulus rolling hash with
O(1)append / slide.
Constants§
- DEFAULT_
BASE - Default base used for the rolling hash.
- DEFAULT_
MOD - Default modulus (a known large prime).
Functions§
- compute_
hash - Compute the polynomial hash of a byte slice.