Skip to main content

Crate rolling_hash

Crate rolling_hash 

Source
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 in O(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§

DoubleRollingHash
Two-modulus rolling hash with combine/equal-friendly semantics.
RollingHash
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.