pub struct Hasher<'params>(/* private fields */);
Expand description
A Hasher
implements one of the two hash 64-bit functions
defined by a specific Params
struct, further tweaked by a
seed. Construct Hasher
s with Params::hasher
,
Params::secondary_hasher
, or Params::component_hasher
.
The hash value is a function of the Params
, the
UmashComponent
, the seed, and of the bytes written to the
Hasher
, but independent of the size of the individual slices
written to the hasher.
In other words, it doesn’t matter how we partition an input, the
Hasher
computes the same hash value as a one-shot UMASH call
for the parameters and the concatenated input bytes.
Implementations§
Source§impl<'params> Hasher<'params>
impl<'params> Hasher<'params>
Sourcepub fn write(&mut self, bytes: &[u8]) -> &mut Self
pub fn write(&mut self, bytes: &[u8]) -> &mut Self
Updates the hash state by conceptually concatenating bytes
to the hash input.
Examples found in repository?
4fn main() {
5 let args: Vec<String> = std::env::args().collect();
6 let input = args
7 .get(1)
8 .cloned()
9 .unwrap_or_else(|| "default input".to_string());
10 let seed = 42u64;
11 let my_params = umash::Params::derive(0, "hello example.c".as_bytes());
12 let fprint = my_params
13 .fingerprinter(seed)
14 .write(input.as_bytes())
15 .digest();
16
17 println!("Input: {}", input);
18 println!("Fingerprint: {:x}, {:x}", fprint.hash[0], fprint.hash[1]);
19 println!(
20 "Hash 0: {:x}",
21 my_params.hasher(seed).write(input.as_bytes()).digest()
22 );
23 println!(
24 "Hash 1: {:x}",
25 my_params
26 .secondary_hasher(seed)
27 .write(input.as_bytes())
28 .digest()
29 );
30
31 let mut h: umash::Hasher = (&my_params).into();
32 h.write(input.as_bytes());
33 println!("Hash: {:x}", h.finish());
34}
Sourcepub fn digest(&self) -> u64
pub fn digest(&self) -> u64
Returns the 64-bit hash value for the Hasher
’s Params
and the bytes passed to Hasher::write
so far.
Examples found in repository?
4fn main() {
5 let args: Vec<String> = std::env::args().collect();
6 let input = args
7 .get(1)
8 .cloned()
9 .unwrap_or_else(|| "default input".to_string());
10 let seed = 42u64;
11 let my_params = umash::Params::derive(0, "hello example.c".as_bytes());
12 let fprint = my_params
13 .fingerprinter(seed)
14 .write(input.as_bytes())
15 .digest();
16
17 println!("Input: {}", input);
18 println!("Fingerprint: {:x}, {:x}", fprint.hash[0], fprint.hash[1]);
19 println!(
20 "Hash 0: {:x}",
21 my_params.hasher(seed).write(input.as_bytes()).digest()
22 );
23 println!(
24 "Hash 1: {:x}",
25 my_params
26 .secondary_hasher(seed)
27 .write(input.as_bytes())
28 .digest()
29 );
30
31 let mut h: umash::Hasher = (&my_params).into();
32 h.write(input.as_bytes());
33 println!("Hash: {:x}", h.finish());
34}
Trait Implementations§
Source§impl Hasher for Hasher<'_>
UMASH’s collision probability bounds only hold if different
object
s feed different byte streams to the hasher. The standard
Rust [std::Hash::hash
] implementations (and automatically
generated ones) satisfy this requirement for values of the same
type.
impl Hasher for Hasher<'_>
UMASH’s collision probability bounds only hold if different
object
s feed different byte streams to the hasher. The standard
Rust [std::Hash::hash
] implementations (and automatically
generated ones) satisfy this requirement for values of the same
type.
1.26.0 · Source§fn write_u128(&mut self, i: u128)
fn write_u128(&mut self, i: u128)
u128
into this hasher.1.3.0 · Source§fn write_usize(&mut self, i: usize)
fn write_usize(&mut self, i: usize)
usize
into this hasher.1.26.0 · Source§fn write_i128(&mut self, i: i128)
fn write_i128(&mut self, i: i128)
i128
into this hasher.1.3.0 · Source§fn write_isize(&mut self, i: isize)
fn write_isize(&mut self, i: isize)
isize
into this hasher.Source§fn write_length_prefix(&mut self, len: usize)
fn write_length_prefix(&mut self, len: usize)
hasher_prefixfree_extras
)Source§impl Write for Hasher<'_>
Hasher
s compute the same hash value for a given sequence of
bytes, regardless of the number of bytes in each write
call.
This makes it possible to compute a hash by calling a
serialisation function.
impl Write for Hasher<'_>
Hasher
s compute the same hash value for a given sequence of
bytes, regardless of the number of bytes in each write
call.
This makes it possible to compute a hash by calling a
serialisation function.
Call Hasher::digest
to find the hash value for the
concatenation of all the bytes written to the Hasher
.
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flushing a Hasher
cannot compute the fingerprint, due to
the trait’s interface; the implementation is a no-op.
See Hasher::digest
.
Source§fn write(&mut self, bytes: &[u8]) -> Result<usize>
fn write(&mut self, bytes: &[u8]) -> Result<usize>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)