ihash 0.1.2

World's fastest high-quality non-cryptographic hash, deterministic cross-platform XOF, and seekable stream cipher
Documentation
//! World's fastest high-quality non-cryptographic hash, deterministic cross-platform XOF, and seekable stream cipher.

#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]

mod arch;
mod backend;
#[cfg(feature = "c")]
#[cfg_attr(docsrs, doc(cfg(feature = "c")))]
pub mod c;
mod const_fn;
#[cfg(feature = "cpu")]
#[cfg_attr(docsrs, doc(cfg(feature = "cpu")))]
pub mod cpu;
mod hasher;
#[cfg(feature = "std")]
mod map;
pub mod seed;
mod state;
mod stream;

pub use hasher::{IBuildHasher, IHasher};
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub use map::{HashMap, HashMapExt, HashSet, HashSetExt};
pub use stream::Stream;

use crate::{
  arch::Active,
  backend::{ActiveBackend, Platform},
  stream::fill_xof_root,
};

/// Computes a deterministic 32-bit hash equal to the low 32 bits of [`hash64`].
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash32(data: &[u8]) -> u32 {
  Active::hash32::<true>(data, 0)
}

/// Computes a deterministic 64-bit hash equal to the low 64 bits of [`hash128`].
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash64(data: &[u8]) -> u64 {
  Active::hash64::<true>(data, 0)
}

/// Computes a deterministic 128-bit hash equal to the low 128 bits of [`hash256`].
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash128(data: &[u8]) -> u128 {
  Active::hash128::<true>(data, 0)
}

/// Computes a deterministic 256-bit hash equal to the first 32 bytes of [`hash_xof`].
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash256(data: &[u8]) -> [u8; 32] {
  Active::hash256::<true>(data, 0)
}

/// Fills `out` with a deterministic arbitrary-length extendable-output digest (`XOF`).
#[inline]
pub fn hash_xof(data: &[u8], out: &mut [u8]) {
  if out.is_empty() {
    return;
  }
  fill_xof_root(hash256(data), out, ActiveBackend);
}