ihash 0.1.2

World's fastest high-quality non-cryptographic hash, deterministic cross-platform XOF, and seekable stream cipher
Documentation
mod hasher;
pub mod seed;
mod stream;
mod vperm;

#[cfg(feature = "std")]
use std::collections::{HashMap as StdHashMap, HashSet as StdHashSet};

use fearless_simd::Level;
pub use hasher::{IBuildHasher, IHasher};
use seed::{DetectLevel, hash_xof_with, hash128_with, hash256_with};
pub use stream::Stream;

/// `std::collections::HashMap` preconfigured with pure-CPU [`IBuildHasher`].
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub type HashMap<K, V> = StdHashMap<K, V, IBuildHasher>;

/// `std::collections::HashSet` preconfigured with pure-CPU [`IBuildHasher`].
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub type HashSet<T> = StdHashSet<T, IBuildHasher>;

/// Computes a 32-bit hash without AES hardware intrinsics, using an explicit `fearless_simd::Level`.
#[must_use]
#[inline]
pub fn hash32_with_level(data: &[u8], level: Level) -> u32 {
  hash64_with_level(data, level) as u32
}

/// Computes a 64-bit hash without AES hardware intrinsics, using an explicit `fearless_simd::Level`.
#[must_use]
#[inline]
pub fn hash64_with_level(data: &[u8], level: Level) -> u64 {
  hash128_with_level(data, level) as u64
}

/// Computes a 128-bit hash without AES hardware intrinsics, using an explicit `fearless_simd::Level`.
#[must_use]
#[inline]
pub fn hash128_with_level(data: &[u8], level: Level) -> u128 {
  hash128_with::<true>(data, 0, level)
}

/// Computes a 256-bit hash without AES hardware intrinsics, using an explicit `fearless_simd::Level`.
#[must_use]
#[inline]
pub fn hash256_with_level(data: &[u8], level: Level) -> [u8; 32] {
  hash256_with::<true>(data, 0, level)
}

/// Computes an arbitrary-length XOF digest without AES hardware intrinsics, using `level`.
#[inline]
pub fn hash_xof_with_level(data: &[u8], out: &mut [u8], level: Level) {
  hash_xof_with::<true>(data, 0, out, level);
}

/// Computes a 32-bit hash using pure-CPU software AES via `fearless_simd`.
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash32(data: &[u8]) -> u32 {
  hash64(data) as u32
}

/// Computes a 64-bit hash using pure-CPU software AES via `fearless_simd`.
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash64(data: &[u8]) -> u64 {
  hash128(data) as u64
}

/// Computes a 128-bit hash using pure-CPU software AES via `fearless_simd`.
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash128(data: &[u8]) -> u128 {
  hash128_with::<true>(data, 0, DetectLevel)
}

/// Computes a 256-bit hash using pure-CPU software AES via `fearless_simd`.
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash256(data: &[u8]) -> [u8; 32] {
  hash256_with::<true>(data, 0, DetectLevel)
}

/// Fills `out` with an arbitrary-length XOF digest using pure-CPU software AES.
#[inline]
pub fn hash_xof(data: &[u8], out: &mut [u8]) {
  hash_xof_with::<true>(data, 0, out, DetectLevel);
}