pub struct DefaultHasher { /* private fields */ }Expand description
A fast, non-cryptographic 64-bit hasher with strong avalanche behaviour.
DefaultHasher folds the input eight bytes at a time through a 64x64-bit
multiply-fold and mixes the total length into the finalizer, so inputs that
differ only by trailing zero bytes do not collide. It is not suitable for
authentication or any setting where collision resistance against an
adversary is required; use a cryptographic hash for that.
You rarely construct this directly. It is produced by
DefaultHashBuilder, which the structures use by default.
§Examples
use core::hash::{Hash, Hasher};
use bloom_lib::hash::DefaultHasher;
let mut hasher = DefaultHasher::default();
"probabilistic".hash(&mut hasher);
let digest = hasher.finish();
// Hashing the same value again yields the same digest.
let mut again = DefaultHasher::default();
"probabilistic".hash(&mut again);
assert_eq!(digest, again.finish());Implementations§
Source§impl DefaultHasher
impl DefaultHasher
Sourcepub const fn with_seed(seed: u64) -> Self
pub const fn with_seed(seed: u64) -> Self
Creates a hasher seeded with the given value.
Two hashers created with the same seed produce identical digests for
identical inputs. DefaultHasher::default uses a fixed library seed.
§Examples
use core::hash::Hasher;
use bloom_lib::hash::DefaultHasher;
let mut a = DefaultHasher::with_seed(42);
let mut b = DefaultHasher::with_seed(7);
a.write(b"payload");
b.write(b"payload");
assert_ne!(a.finish(), b.finish());Trait Implementations§
Source§impl Clone for DefaultHasher
impl Clone for DefaultHasher
Source§fn clone(&self) -> DefaultHasher
fn clone(&self) -> DefaultHasher
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 DefaultHasher
impl Debug for DefaultHasher
Source§impl Default for DefaultHasher
impl Default for DefaultHasher
Source§impl Hasher for DefaultHasher
impl Hasher for DefaultHasher
1.26.0 · Source§fn write_u128(&mut self, i: u128)
fn write_u128(&mut self, i: u128)
Writes a single
u128 into this hasher.1.3.0 · Source§fn write_usize(&mut self, i: usize)
fn write_usize(&mut self, i: usize)
Writes a single
usize into this hasher.1.26.0 · Source§fn write_i128(&mut self, i: i128)
fn write_i128(&mut self, i: i128)
Writes a single
i128 into this hasher.1.3.0 · Source§fn write_isize(&mut self, i: isize)
fn write_isize(&mut self, i: isize)
Writes a single
isize into this hasher.Source§fn write_length_prefix(&mut self, len: usize)
fn write_length_prefix(&mut self, len: usize)
🔬This is a nightly-only experimental API. (
hasher_prefixfree_extras)Writes a length prefix into this hasher, as part of being prefix-free. Read more
Auto Trait Implementations§
impl Freeze for DefaultHasher
impl RefUnwindSafe for DefaultHasher
impl Send for DefaultHasher
impl Sync for DefaultHasher
impl Unpin for DefaultHasher
impl UnsafeUnpin for DefaultHasher
impl UnwindSafe for DefaultHasher
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