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};
pub type HashMap<K, V> = StdHashMap<K, V, IBuildHasher>;
pub type HashSet<T> = StdHashSet<T, IBuildHasher>;
pub trait HashMapExt<K, V> {
fn new() -> Self;
fn with_capacity(capacity: usize) -> Self;
}
pub trait HashSetExt<T> {
fn new() -> Self;
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);