pub struct GxHasher { /* private fields */ }Expand description
A Hasher for hashing an arbitrary stream of bytes.
§Features
- The fastest
Hasherof its class1, for all input sizes - Highly collision resitant
- DOS resistance thanks to seed randomization when using
GxHasher::default()
1There might me faster alternatives, such as fxhash for very small input sizes, but that usually have low quality properties.
Implementations§
Source§impl GxHasher
impl GxHasher
Sourcepub fn with_seed(seed: i64) -> GxHasher
pub fn with_seed(seed: i64) -> GxHasher
Creates a new hasher using the provided seed.
§Warning ⚠️
Hardcoding a seed may make your Hasher vulnerable to DOS attacks.
It is recommended to use GxBuildHasher::default() for improved DOS resistance.
§Example
use std::hash::Hasher;
use gxhash::GxHasher;
let mut hasher = GxHasher::with_seed(1234);
hasher.write(b"Hello");
hasher.write_u32(123);
hasher.write_u8(42);
println!("Hash is {:x}!", hasher.finish());Sourcepub fn finish_u128(&self) -> u128
pub fn finish_u128(&self) -> u128
Finish this hasher and return the hashed value as a 128 bit unsigned integer.
Trait Implementations§
Source§impl Default for GxHasher
impl Default for GxHasher
Source§fn default() -> GxHasher
fn default() -> GxHasher
Creates a new hasher with a empty seed.
§Warning ⚠️
Not using a seed may make your Hasher vulnerable to DOS attacks.
It is recommended to use GxBuildHasher::default() for improved DOS resistance.
§Example
use std::hash::Hasher;
use gxhash::GxHasher;
let mut hasher = GxHasher::default();
hasher.write(b"Hello");
hasher.write_u32(123);
hasher.write_u8(42);
println!("Hash is {:x}!", hasher.finish());Source§impl Hasher for GxHasher
impl Hasher for GxHasher
Source§fn write_u128(&mut self, value: u128)
fn write_u128(&mut self, value: u128)
Writes a single
u128 into this hasher.Source§fn write_i128(&mut self, value: i128)
fn write_i128(&mut self, value: i128)
Writes a single
i128 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.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 GxHasher
impl RefUnwindSafe for GxHasher
impl Send for GxHasher
impl Sync for GxHasher
impl Unpin for GxHasher
impl UnwindSafe for GxHasher
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