Skip to main content

RapidStreamHasherInlineV3

Struct RapidStreamHasherInlineV3 

Source
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>

Source

pub fn new(secrets: &'a RapidSecrets) -> Self

Create a new RapidStreamHasher with seed and secrets.

Source

pub fn write(&mut self, data: &[u8])

Write data to the stream hasher.

Source

pub fn finish(&self) -> u64

Finalize a hash from the hasher state.

Source

pub fn reset(&mut self)

Reuse the buffer within this RapidStreamHasher.

Auto Trait Implementations§

§

impl<'a, const AVALANCHE: bool, const PROTECTED: bool> Freeze for RapidStreamHasherInlineV3<'a, AVALANCHE, PROTECTED>

§

impl<'a, const AVALANCHE: bool, const PROTECTED: bool> RefUnwindSafe for RapidStreamHasherInlineV3<'a, AVALANCHE, PROTECTED>

§

impl<'a, const AVALANCHE: bool, const PROTECTED: bool> Send for RapidStreamHasherInlineV3<'a, AVALANCHE, PROTECTED>

§

impl<'a, const AVALANCHE: bool, const PROTECTED: bool> Sync for RapidStreamHasherInlineV3<'a, AVALANCHE, PROTECTED>

§

impl<'a, const AVALANCHE: bool, const PROTECTED: bool> Unpin for RapidStreamHasherInlineV3<'a, AVALANCHE, PROTECTED>

§

impl<'a, const AVALANCHE: bool, const PROTECTED: bool> UnsafeUnpin for RapidStreamHasherInlineV3<'a, AVALANCHE, PROTECTED>

§

impl<'a, const AVALANCHE: bool, const PROTECTED: bool> UnwindSafe for RapidStreamHasherInlineV3<'a, AVALANCHE, PROTECTED>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.