ihash 0.1.2

World's fastest high-quality non-cryptographic hash, deterministic cross-platform XOF, and seekable stream cipher
Documentation
use std::collections::{HashMap as StdHashMap, HashSet as StdHashSet};

use crate::IBuildHasher;
#[cfg(feature = "cpu")]
use crate::cpu::{HashMap as CpuHashMap, HashSet as CpuHashSet, IBuildHasher as CpuBuildHasher};

/// `std::collections::HashMap` preconfigured with `IBuildHasher`.
pub type HashMap<K, V> = StdHashMap<K, V, IBuildHasher>;

/// `std::collections::HashSet` preconfigured with `IBuildHasher`.
pub type HashSet<T> = StdHashSet<T, IBuildHasher>;

/// Convenience constructors for `ihash::HashMap` and `ihash::cpu::HashMap`.
pub trait HashMapExt<K, V> {
  /// Creates an empty map using the default per-thread randomized build hasher.
  fn new() -> Self;

  /// Creates an empty map with at least the specified capacity.
  fn with_capacity(capacity: usize) -> Self;
}

/// Convenience constructors for `ihash::HashSet` and `ihash::cpu::HashSet`.
pub trait HashSetExt<T> {
  /// Creates an empty set using the default per-thread randomized build hasher.
  fn new() -> Self;

  /// Creates an empty set with at least the specified capacity.
  fn with_capacity(capacity: usize) -> Self;
}

macro_rules! impl_collection_ext {
  ($trait:ident, $std_ty:ident, $target:ty, $bh:ty, $($param:ident),+) => {
    impl<$($param),+> $trait<$($param),+> for $target {
      #[inline(always)]
      fn new() -> Self {
        $std_ty::with_hasher(<$bh>::default())
      }

      #[inline(always)]
      fn with_capacity(capacity: usize) -> Self {
        $std_ty::with_capacity_and_hasher(capacity, <$bh>::default())
      }
    }
  };
}

impl_collection_ext!(HashMapExt, StdHashMap, HashMap<K, V>, IBuildHasher, K, V);
impl_collection_ext!(HashSetExt, StdHashSet, HashSet<T>, IBuildHasher, T);
#[cfg(feature = "cpu")]
impl_collection_ext!(
  HashMapExt,
  StdHashMap,
  CpuHashMap<K, V>,
  CpuBuildHasher,
  K,
  V
);
#[cfg(feature = "cpu")]
impl_collection_ext!(HashSetExt, StdHashSet, CpuHashSet<T>, CpuBuildHasher, T);