pub struct DictMap<K: Eq + Hash, V> { /* private fields */ }Expand description
Generic typed map keyed by K with an ahash hasher.
The wrapper exposes the small set of operations used by the rest
of the engine and intentionally hides the underlying hasher and
table layout. Use DictMap::iter for read-only traversal and
DictMap::drain when you need to consume the entire map.
§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<&'static str, u32> = DictMap::new();
m.insert("k", 7);
assert_eq!(m.get(&"k"), Some(&7));
assert_eq!(m.len(), 1);
assert!(m.remove(&"k").is_some());
assert!(m.is_empty());Implementations§
Source§impl<K: Eq + Hash, V> DictMap<K, V>
impl<K: Eq + Hash, V> DictMap<K, V>
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct an empty map.
§Examples
use dynomite::util::dict::DictMap;
let m: DictMap<u32, u32> = DictMap::new();
assert!(m.is_empty());Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Construct an empty map with at least capacity slots.
§Examples
use dynomite::util::dict::DictMap;
let m: DictMap<u32, u32> = DictMap::with_capacity(8);
assert!(m.is_empty());Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Insert value at key, returning the previous value (if any).
§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
assert_eq!(m.insert(1, 10), None);
assert_eq!(m.insert(1, 20), Some(10));Sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Remove and return the value at key.
§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
assert_eq!(m.remove(&1), Some(10));
assert_eq!(m.remove(&1), None);Sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Look up an immutable reference to the value at key.
§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
assert_eq!(m.get(&1), Some(&10));Sourcepub fn get_mut(&mut self, key: &K) -> Option<&mut V>
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>
Look up a mutable reference to the value at key.
§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
*m.get_mut(&1).unwrap() = 20;
assert_eq!(m.get(&1), Some(&20));Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Whether key is in the map.
§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
assert!(m.contains_key(&1));
assert!(!m.contains_key(&2));Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of entries.
§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
assert_eq!(m.len(), 1);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the map is empty.
§Examples
use dynomite::util::dict::DictMap;
let m: DictMap<u32, u32> = DictMap::new();
assert!(m.is_empty());Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drop every entry.
§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
m.clear();
assert!(m.is_empty());Sourcepub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
Borrowed iterator over (key, value) pairs.
§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
m.insert(2, 20);
let mut sum = 0u32;
for (_k, v) in m.iter() { sum += v; }
assert_eq!(sum, 30);Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
Mutable iterator over (key, value) pairs.
§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
for (_k, v) in m.iter_mut() { *v += 1; }
assert_eq!(m.get(&1), Some(&11));Sourcepub fn drain(&mut self) -> impl Iterator<Item = (K, V)> + '_
pub fn drain(&mut self) -> impl Iterator<Item = (K, V)> + '_
Consume the map and yield (key, value) pairs.
§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
let drained: Vec<_> = m.drain().collect();
assert_eq!(drained, vec![(1, 10)]);
assert!(m.is_empty());