Skip to main content

roll

Function roll 

Source
pub fn roll(
    current: u64,
    outgoing: u64,
    incoming: u64,
    window_power: u64,
) -> u64
Expand description

Roll the hash one position: remove outgoing (the token leaving the window), add incoming (the token entering the window).

window_power must be precomputed by the caller as base_pow(window_size - 1) once per format group before the sliding-window loop — not on every call. This eliminates an O(window_size) loop from the hot path.

If per-language min_tokens is introduced in future, recompute window_power per detect_in_group invocation using that group’s min_tokens value.

new_hash = (current - outgoing * window_power) * BASE + incoming All arithmetic is wrapping.