pub struct OrdinalMap<K, V> { /* private fields */ }Expand description
Map Ordinal keys to values.
Map operations are constant time
(provided that K::ordinal() is constant time).
This implementation allocates a boxed slice [Option<V>; K::ORDINAL_SIZE]
on the first insertion. For non-allocating map, consider using
OrdinalArrayMap.
This implementation is sparse (not every key has an associated value).
For a total map, see OrdinalTotalMap
and OrdinalTotalArrayMap.
Implementations§
Source§impl<K: Ordinal, V> OrdinalMap<K, V>
impl<K: Ordinal, V> OrdinalMap<K, V>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty map. This operation does not allocate memory, but first insertion allocates the whole map.
Sourcepub fn get<'a>(&'a self, key: &K) -> Option<&'a V>
pub fn get<'a>(&'a self, key: &K) -> Option<&'a V>
Returns a reference to the value corresponding to the key.
Sourcepub fn get_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V>
pub fn get_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V>
Returns a mutable reference to the value corresponding to the key.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true if the map contains the key.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the map. This is an O(K::ORDINAL_SIZE) operation.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Insert a value into the map, returning the previous value if it existed.
Sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Remove a value from the map, returning it if it existed.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
Iterate over the mutable references to the values of the map.