pub struct RollingHashWindow { /* private fields */ }Expand description
Rolling hash window for fast substring detection.
Maintains rolling hash values over accumulated content using the Rabin-Karp algorithm. Provides O(1) hash computation for sliding windows.
§Algorithm
Uses polynomial rolling hash with base 256 (byte values) and modulus from a large prime to minimize collisions.
Hash computation:
hash(s[0..n]) = (s[0] * b^(n-1) + s[1] * b^(n-2) + ... + s[n-1]) mod mRolling update:
hash(s[i+1..i+n+1]) = ((hash(s[i..i+n]) - s[i] * b^(n-1)) * b + s[i+n]) mod m§Example
ⓘ
let mut window = RollingHashWindow::new();
window.add_content("Hello World");
// Check if "World" exists in the accumulated content
let hashes = window.get_window_hashes(5); // 5 = length of "World"
let world_hash = RollingHashWindow::compute_hash("World");
if hashes.contains(&world_hash) {
// Potential match - verify with KMP
}Implementations§
Source§impl RollingHashWindow
impl RollingHashWindow
Sourcepub fn compute_hash(text: &str) -> u64
pub fn compute_hash(text: &str) -> u64
Trait Implementations§
Source§impl Clone for RollingHashWindow
impl Clone for RollingHashWindow
Source§fn clone(&self) -> RollingHashWindow
fn clone(&self) -> RollingHashWindow
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RollingHashWindow
impl Debug for RollingHashWindow
Source§impl Default for RollingHashWindow
impl Default for RollingHashWindow
Source§fn default() -> RollingHashWindow
fn default() -> RollingHashWindow
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for RollingHashWindow
impl RefUnwindSafe for RollingHashWindow
impl Send for RollingHashWindow
impl Sync for RollingHashWindow
impl Unpin for RollingHashWindow
impl UnwindSafe for RollingHashWindow
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more