Skip to content
Permalink
Browse files

add a performance note and a usage example for Hasher

  • Loading branch information
oconnor663 committed Feb 12, 2020
1 parent 38a46ba commit 5dea88983480c117d21ea1c00e3e429e0baa98ca
Showing with 30 additions and 0 deletions.
  1. +30 −0 src/lib.rs
@@ -769,6 +769,36 @@ fn parent_node_output(
/// In addition to its inherent methods, this type implements several commonly
/// used traits from the [`digest`](https://crates.io/crates/digest) and
/// [`crypto_mac`](https://crates.io/crates/crypto-mac) crates.
///
/// **Performance note:** The [`update`] and [`update_with_join`] methods
/// perform poorly when the caller's input buffer is small. See their method
/// docs below. A 16 KiB buffer is large enough to leverage all currently
/// supported SIMD instruction sets.
///
/// # Examples
///
/// ```
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // Hash an input incrementally.
/// let mut hasher = blake3::Hasher::new();
/// hasher.update(b"foo");
/// hasher.update(b"bar");
/// hasher.update(b"baz");
/// assert_eq!(hasher.finalize(), blake3::hash(b"foobarbaz"));
///
/// // Extended output. OutputReader also implements Read and Seek.
/// # #[cfg(feature = "std")] {
/// let mut output = [0; 1000];
/// let mut output_reader = hasher.finalize_xof();
/// output_reader.fill(&mut output);
/// assert_eq!(&output[..32], blake3::hash(b"foobarbaz").as_bytes());
/// # }
/// # Ok(())
/// # }
/// ```
///
/// [`update`]: #method.update
/// [`update_with_join`]: #method.update_with_join
#[derive(Clone)]
pub struct Hasher {
key: CVWords,

0 comments on commit 5dea889

Please sign in to comment.
You can’t perform that action at this time.