use crate::utils::hash::FxBuildHasher;
pub type GrafeoMap<K, V> = hashbrown::HashMap<K, V, FxBuildHasher>;
pub type GrafeoSet<T> = hashbrown::HashSet<T, FxBuildHasher>;
pub type GrafeoConcurrentMap<K, V> = dashmap::DashMap<K, V, FxBuildHasher>;
pub type GrafeoConcurrentSet<T> = dashmap::DashSet<T, FxBuildHasher>;
pub type GrafeoIndexMap<K, V> = indexmap::IndexMap<K, V, FxBuildHasher>;
pub type GrafeoIndexSet<T> = indexmap::IndexSet<T, FxBuildHasher>;
#[inline]
#[must_use]
pub fn grafeo_map<K, V>() -> GrafeoMap<K, V> {
GrafeoMap::with_hasher(FxBuildHasher::default())
}
#[inline]
#[must_use]
pub fn grafeo_map_with_capacity<K, V>(capacity: usize) -> GrafeoMap<K, V> {
GrafeoMap::with_capacity_and_hasher(capacity, FxBuildHasher::default())
}
#[inline]
#[must_use]
pub fn grafeo_set<T>() -> GrafeoSet<T> {
GrafeoSet::with_hasher(FxBuildHasher::default())
}
#[inline]
#[must_use]
pub fn grafeo_set_with_capacity<T>(capacity: usize) -> GrafeoSet<T> {
GrafeoSet::with_capacity_and_hasher(capacity, FxBuildHasher::default())
}
#[inline]
#[must_use]
pub fn grafeo_concurrent_map<K, V>() -> GrafeoConcurrentMap<K, V>
where
K: Eq + std::hash::Hash,
{
GrafeoConcurrentMap::with_hasher(FxBuildHasher::default())
}
#[inline]
#[must_use]
pub fn grafeo_concurrent_map_with_capacity<K, V>(capacity: usize) -> GrafeoConcurrentMap<K, V>
where
K: Eq + std::hash::Hash,
{
GrafeoConcurrentMap::with_capacity_and_hasher(capacity, FxBuildHasher::default())
}
#[inline]
#[must_use]
pub fn grafeo_index_map<K, V>() -> GrafeoIndexMap<K, V> {
GrafeoIndexMap::with_hasher(FxBuildHasher::default())
}
#[inline]
#[must_use]
pub fn grafeo_index_map_with_capacity<K, V>(capacity: usize) -> GrafeoIndexMap<K, V> {
GrafeoIndexMap::with_capacity_and_hasher(capacity, FxBuildHasher::default())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_grafeo_map() {
let mut map = grafeo_map::<String, i32>();
map.insert("key".to_string(), 42);
assert_eq!(map.get("key"), Some(&42));
}
#[test]
fn test_grafeo_set() {
let mut set = grafeo_set::<i32>();
set.insert(1);
set.insert(2);
assert!(set.contains(&1));
assert!(!set.contains(&3));
}
#[test]
fn test_grafeo_concurrent_map() {
let map = grafeo_concurrent_map::<String, i32>();
map.insert("key".to_string(), 42);
assert_eq!(*map.get("key").unwrap(), 42);
}
#[test]
fn test_grafeo_index_map_preserves_order() {
let mut map = grafeo_index_map::<&str, i32>();
map.insert("c", 3);
map.insert("a", 1);
map.insert("b", 2);
let keys: Vec<_> = map.keys().copied().collect();
assert_eq!(keys, vec!["c", "a", "b"]);
}
}