use cfg_if::cfg_if;
mod hasher;
pub use hasher::*;
mod fixed;
pub use fixed::*;
cfg_if! {
if #[cfg(any(feature = "map-hashbrown", not(feature = "std")))] {
use hashbrown as imp;
pub type Entry<'a, K, V, S = DefaultHashBuilder> = imp::hash_map::Entry<'a, K, V, S>;
pub type OccupiedEntry<'a, K, V, S = DefaultHashBuilder> = imp::hash_map::OccupiedEntry<'a, K, V, S>;
pub type VacantEntry<'a, K, V, S = DefaultHashBuilder> = imp::hash_map::VacantEntry<'a, K, V, S>;
} else {
use hashbrown as _;
use std::collections as imp;
#[doc(no_inline)]
pub use imp::hash_map::{Entry, OccupiedEntry, VacantEntry};
}
}
#[doc(no_inline)]
pub use imp::{hash_map, hash_set};
pub type HashMap<K, V, S = DefaultHashBuilder> = imp::HashMap<K, V, S>;
pub type HashSet<V, S = DefaultHashBuilder> = imp::HashSet<V, S>;
cfg_if! {
if #[cfg(feature = "map-indexmap")] {
#[doc(no_inline)]
pub use indexmap::{self, map::Entry as IndexEntry};
pub type IndexMap<K, V, S = DefaultHashBuilder> = indexmap::IndexMap<K, V, S>;
pub type IndexSet<V, S = DefaultHashBuilder> = indexmap::IndexSet<V, S>;
}
}
#[cfg(feature = "rayon")]
pub mod rayon {
use super::*;
cfg_if! {
if #[cfg(any(feature = "map-hashbrown", not(feature = "std")))] {
pub use hashbrown::hash_map::rayon::{
IntoParIter as IntoIter,
ParDrain as Drain,
ParIter as Iter,
ParIterMut as IterMut,
ParKeys as Keys,
ParValues as Values,
ParValuesMut as ValuesMut
};
use ::rayon as _;
} else {
pub use ::rayon::collections::hash_map::*;
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_hasher_builder_traits() {
let hash_builder = <DefaultHashBuilder as Default>::default();
let _hash_builder2 = <DefaultHashBuilder as Clone>::clone(&hash_builder);
let mut hasher =
<DefaultHashBuilder as core::hash::BuildHasher>::build_hasher(&hash_builder);
<DefaultHasher as core::hash::Hasher>::write_u8(&mut hasher, 0);
let _hasher2 = <DefaultHasher as Clone>::clone(&hasher);
}
fn use_entry(e: Entry<'_, u32, u64>) -> u64 {
match e {
Entry::Occupied(o) => {
let o: OccupiedEntry<'_, u32, u64> = o;
*o.get()
}
Entry::Vacant(v) => {
let v: VacantEntry<'_, u32, u64> = v;
*v.insert(0)
}
}
}
#[test]
fn test_entry() {
let mut map = HashMap::<u32, u64>::default();
map.insert(1, 1);
assert_eq!(use_entry(map.entry(0)), 0);
assert_eq!(use_entry(map.entry(1)), 1);
assert_eq!(use_entry(map.entry(2)), 0);
}
}