use crate::fast::RandomState;
pub type RapidHashMap<K, V> = std::collections::HashMap<K, V, RandomState>;
pub type RapidHashSet<K> = std::collections::HashSet<K, RandomState>;
pub trait HashMapExt {
fn new() -> Self;
fn with_capacity(capacity: usize) -> Self;
}
impl<K, V> HashMapExt for RapidHashMap<K, V> {
#[inline]
fn new() -> Self {
RapidHashMap::default()
}
#[inline]
fn with_capacity(capacity: usize) -> Self {
RapidHashMap::with_capacity_and_hasher(capacity, RandomState::default())
}
}
pub trait HashSetExt {
fn new() -> Self;
fn with_capacity(capacity: usize) -> Self;
}
impl<K> HashSetExt for RapidHashSet<K> {
#[inline]
fn new() -> Self {
RapidHashSet::default()
}
#[inline]
fn with_capacity(capacity: usize) -> Self {
RapidHashSet::with_capacity_and_hasher(capacity, RandomState::default())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_hashmap_new() {
let mut map = RapidHashMap::new();
map.insert("key", "value");
assert_eq!(map.get("key"), Some(&"value"));
assert_eq!(map.get("na"), None);
}
#[test]
fn test_hashset_new() {
let mut set = RapidHashSet::new();
set.insert("value");
assert!(set.contains("value"));
assert!(!set.contains("na"));
}
#[test]
fn test_hashmap_size() {
assert_eq!(core::mem::size_of::<RapidHashMap<u64, u64>>(), 40);
}
}