pub struct RapidStreamHasherInlineV3<'a, const AVALANCHE: bool, const PROTECTED: bool> { /* private fields */ }Expand description
A bytewise-style incremental interface for rapidhash.
This interface guarantees incremental inputs are the same as a bulk hash of the same bytes.
See [crate::v3::rapidhash_v3_file] for an alternative Read-based incremental interface.
§Speed
RapidStreamHasher is slower than rapidhash_v3 due to the extra overhead from the incremental
interface. Where possible, we recommend using rapidhash_v3 for bulk hashing.
This will copy bytes, except where written chunks are larger than 112 bytes. Larger chunks will perform better than smaller chunks by avoiding copying.
§Portability
RapidStreamHasher does not implement std::hash::Hasher and is specially designed to produce
stable hashes across platforms and compiler versions. Any changes to hash output in
RapidStreamHasher will result in a major crate bump.
We’re aiming to support the portable-hash crate in
the future to enable derive(PortableHash) on user-defined types. Please leave a comment or
upvote if this would be useful to you on a large project.
§Example
use rapidhash::v3::{rapidhash_v3_seeded, RapidSecrets, RapidStreamHasherV3};
let secrets = RapidSecrets::seed(0);
let data: &[u8] = [0, 1, 2, 3, 4, 5, 6, 7].as_slice();
// classic rapidhash v3
let expected_hash = rapidhash_v3_seeded(data, &secrets);
// incremental rapidhash v3
let mut hasher = RapidStreamHasherV3::new(&secrets);
hasher.write(&data[0..3]);
hasher.write(&data[3..6]);
hasher.write(&data[6..]);
let actual_hash = hasher.finish();
// equal hashes!
assert_eq!(expected_hash, actual_hash);Implementations§
Source§impl<'a, const AVALANCHE: bool, const PROTECTED: bool> RapidStreamHasherInlineV3<'a, AVALANCHE, PROTECTED>
impl<'a, const AVALANCHE: bool, const PROTECTED: bool> RapidStreamHasherInlineV3<'a, AVALANCHE, PROTECTED>
Sourcepub fn new(secrets: &'a RapidSecrets) -> Self
pub fn new(secrets: &'a RapidSecrets) -> Self
Create a new RapidStreamHasher with seed and secrets.