pub struct RollingHash { /* private fields */ }
Expand description
Hasher which computes a variant of 32-bit rolling hash as used in ssdeep.
In ssdeep, this is the most important hash function to decide whether to trigger a context update based on the last 7 bytes it met.
Specifically, RollingHash
implements the rolling hash implemented in
ssdeep version 2.13 or later. This is the first version that officially
supported ≧4GiB files and implemented a true rolling hash function.
Implementations§
Source§impl RollingHash
impl RollingHash
Sourcepub const WINDOW_SIZE: usize = 7usize
pub const WINDOW_SIZE: usize = 7usize
The window size of the rolling hash.
This is 7 bytes in ssdeep.
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new RollingHash
with the initial value.
Sourcepub fn update_by_byte(&mut self, ch: u8) -> &mut Self
pub fn update_by_byte(&mut self, ch: u8) -> &mut Self
Updates the hash value by processing a byte.
Sourcepub fn update_by_iter(&mut self, iter: impl Iterator<Item = u8>) -> &mut Self
pub fn update_by_iter(&mut self, iter: impl Iterator<Item = u8>) -> &mut Self
Updates the hash value by processing an iterator of u8
.
Sourcepub fn update(&mut self, buf: &[u8]) -> &mut Self
pub fn update(&mut self, buf: &[u8]) -> &mut Self
Updates the hash value by processing a slice of u8
.
Sourcepub fn value(&self) -> u32
pub fn value(&self) -> u32
Returns the current hash value.
Note that there’s no “finalization” on this rolling hash. You can even continue updating after reading the hash value.
This is the sum of its three internal states (h1
, h2
, and h3
).
See the source code and the private documentation for
its mathematical details.
Trait Implementations§
Source§impl AddAssign<&[u8]> for RollingHash
impl AddAssign<&[u8]> for RollingHash
Source§fn add_assign(&mut self, buffer: &[u8])
fn add_assign(&mut self, buffer: &[u8])
Updates the hash value by processing a slice of u8
.
Source§impl AddAssign<u8> for RollingHash
impl AddAssign<u8> for RollingHash
Source§fn add_assign(&mut self, byte: u8)
fn add_assign(&mut self, byte: u8)
Updates the hash value by processing a byte.
Source§impl Clone for RollingHash
impl Clone for RollingHash
Source§fn clone(&self) -> RollingHash
fn clone(&self) -> RollingHash
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more