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());Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for DictMap<K, V>
impl<K, V> RefUnwindSafe for DictMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for DictMap<K, V>
impl<K, V> Sync for DictMap<K, V>
impl<K, V> Unpin for DictMap<K, V>
impl<K, V> UnsafeUnpin for DictMap<K, V>
impl<K, V> UnwindSafe for DictMap<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.