#[cfg(feature = "std")]
use crate::map::{HashMap, HashSet};
use crate::{
arch::Active,
backend::{ActiveBackend, Platform},
hasher::{IBuildHasher, IHasher},
stream::{Stream, fill_xof_root},
};
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash32(data: &[u8], seed: u64) -> u32 {
Active::hash32::<false>(data, seed)
}
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash64(data: &[u8], seed: u64) -> u64 {
Active::hash64::<false>(data, seed)
}
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash128(data: &[u8], seed: u64) -> u128 {
Active::hash128::<false>(data, seed)
}
#[must_use]
#[cfg_attr(not(debug_assertions), inline(always))]
#[cfg_attr(debug_assertions, inline)]
pub fn hash256(data: &[u8], seed: u64) -> [u8; 32] {
Active::hash256::<false>(data, seed)
}
#[inline]
pub fn hash_xof(data: &[u8], seed: u64, out: &mut [u8]) {
if out.is_empty() {
return;
}
fill_xof_root(hash256(data, seed), out, ActiveBackend);
}
#[must_use]
#[inline]
pub fn stream(data: &[u8], seed: u64) -> Stream {
Stream::from_root(hash256(data, seed))
}
#[must_use]
#[inline]
pub fn keystream(seed: u64) -> Stream {
stream(&[], seed)
}
#[must_use]
#[inline]
pub const fn hasher(seed: u64) -> IHasher {
IHasher::with_seed(seed)
}
#[must_use]
#[inline]
pub const fn build_hasher(seed: u64) -> IBuildHasher {
IBuildHasher::with_seed(seed)
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[must_use]
#[inline(always)]
pub fn hash_map<K, V>(seed: u64) -> HashMap<K, V> {
HashMap::with_hasher(build_hasher(seed))
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[must_use]
#[inline(always)]
pub fn hash_set<T>(seed: u64) -> HashSet<T> {
HashSet::with_hasher(build_hasher(seed))
}