Struct idmap::IdMap [−][src]
pub struct IdMap<K: IntegerId, V, T: EntryTable<K, V> = DenseEntryTable<K, V>> { /* fields omitted */ }
Expand description
A map of mostly-contiguous IntegerId
keys to values, backed by a Vec
.
This is parametric over the type of the underlying EntryTable
, which controls its behavior
By default it’s equivalent to an OrderedIdMap
,
though you can explicitly request a DirectIdMap
instead.
From the user’s perspective, this is equivalent to a nice wrapper around a Vec<Option<(K, V)>>
,
that preserves insertion order and saves some space for missing keys.
More details on the possible internal representations
are documented in the OrderedIdMap
and DirectIdMap
aliases.
Implementations
Create a new direct IdMap.
This stores its entries directly in a Vector
Create new direct IdMap, initialized with the specified capacity
Because a direct id map stores its values directly, the capacity hints at the maximum id and not the length
Create an IdMap with the specified capacity, using an OrderedIdTable
Create a new IdMap
with the specified capacity but a custom entry table.
The length of this map
This doesn’t necessarily equal the maximum integer id
If this map contains the specified key
Retrieve the value associated with the specified key,
or None
if the value is not present
Keys that implement IntegerId
are expected to be cheap,
so we don’t borrow the key.
Retrieve a mutable reference to the value associated with the specified key,
or None
if the value is not present
Insert the specified value, associating it with a key
Returns the value previously associated with they key,
or None
if there wasn’t any
Remove the value associated with the specified key,
or None
if there isn’t any
Retrieve the entry associated with the specified key
Mimics the HashMap entry aPI
Iterate over all the keys and values in this map
Iterate over all the entries in this map, giving mutable references to the keys
Iterate over all the keys in the map
Iterate over all the values in the map
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V, T>ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V, T>ⓘ
Iterate over mutable references to all the values in the map
Clear all the entries the map
Like Vec::clear this should retain the underlying memory for future use.
Retains only the elements specified by the predicate.
let mut map: IdMap<usize, usize> = (0..8).map(|x|(x, x*10)).collect();
map.retain(|k, _| k % 2 == 0);
assert_eq!(
map.into_iter().collect::<Vec<_>>(),
vec![(0, 0), (2, 20), (4, 40), (6, 60)]
);
Reserve space for the specified number of additional elements
Trait Implementations
impl<'de, K, V, T> Deserialize<'de> for IdMap<K, V, T> where
K: Deserialize<'de>,
T: EntryTable<K, V>,
K: IntegerId,
V: Deserialize<'de>,
impl<'de, K, V, T> Deserialize<'de> for IdMap<K, V, T> where
K: Deserialize<'de>,
T: EntryTable<K, V>,
K: IntegerId,
V: Deserialize<'de>,
Deserialize this value from the given Serde deserializer. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
impl<'a, K: IntegerId + 'a, V: 'a, T: 'a> IntoIterator for &'a IdMap<K, V, T> where
T: EntryTable<K, V>,
impl<'a, K: IntegerId + 'a, V: 'a, T: 'a> IntoIterator for &'a IdMap<K, V, T> where
T: EntryTable<K, V>,
impl<'a, K, V, T> IntoIterator for &'a mut IdMap<K, V, T> where
T: EntryTable<K, V>,
K: IntegerId + 'a,
V: 'a,
T: 'a,
impl<'a, K, V, T> IntoIterator for &'a mut IdMap<K, V, T> where
T: EntryTable<K, V>,
K: IntegerId + 'a,
V: 'a,
T: 'a,
impl<K, V1, T1, V2, T2> PartialEq<IdMap<K, V2, T2>> for IdMap<K, V1, T1> where
K: IntegerId,
V1: PartialEq<V2>,
T1: EntryTable<K, V1>,
T2: EntryTable<K, V2>,
impl<K, V1, T1, V2, T2> PartialEq<IdMap<K, V2, T2>> for IdMap<K, V1, T1> where
K: IntegerId,
V1: PartialEq<V2>,
T1: EntryTable<K, V1>,
T2: EntryTable<K, V2>,
Checks if two have the same contents, ignoring the order.
Auto Trait Implementations
impl<K, V, T> RefUnwindSafe for IdMap<K, V, T> where
K: RefUnwindSafe,
T: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, T> UnwindSafe for IdMap<K, V, T> where
K: UnwindSafe,
T: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more