pub struct Map<V> { /* private fields */ }
Expand description
A map with a fixed capacity and usize
as keys.
Implementations§
Source§impl<V: Clone> Map<V>
impl<V: Clone> Map<V>
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Sourcepub fn with_capacity_none(cap: usize) -> Self
pub fn with_capacity_none(cap: usize) -> Self
Make it and prepare all keys.
This is a more expensive operation that with_capacity
, because it has
to go through all keys and fill them up with None
.
§Panics
May panic if out of memory.
Sourcepub fn with_capacity_some(cap: usize, v: V) -> Self
pub fn with_capacity_some(cap: usize, v: V) -> Self
Make it and prepare all keys with some value set.
This is a more expensive operation that with_capacity
, because it has
to go through all keys and fill them up with Some
.
§Panics
May panic if out of memory.
Source§impl<V: Clone> Map<V>
impl<V: Clone> Map<V>
Sourcepub const fn iter_mut(&self) -> IterMut<'_, V> ⓘ
pub const fn iter_mut(&self) -> IterMut<'_, V> ⓘ
Make a mutable iterator over all items.
For example:
use emap::Map;
let mut m: Map<String> = Map::with_capacity_none(16);
m.insert(0, "Jeff".to_string());
m.insert(1, "Lebowski".to_string());
for (_, v) in m.iter_mut() {
*v = v.to_lowercase();
}
The keys are not mutable, only the values, for obvious reasons.
§Panics
It may panic in debug mode, if the Map
is not initialized.
Source§impl<V: Clone> Map<V>
impl<V: Clone> Map<V>
Sourcepub fn contains_key(&self, k: usize) -> bool
pub fn contains_key(&self, k: usize) -> bool
Does the map contain this key?
§Panics
It may panic if you attempt to refer to they key that is outside
of the boundary of this map. It will not return None
, it will panic.
However, in “release” mode it will not panic, but will lead to
undefined behavior.
Sourcepub fn remove(&mut self, k: usize)
pub fn remove(&mut self, k: usize)
Remove by key.
§Panics
It may panic if you attempt to refer to they key that is outside
of the boundary of this map. It will not return None
, it will panic.
However, in “release” mode it will not panic, but will lead to
undefined behavior.
Sourcepub fn insert(&mut self, k: usize, v: V)
pub fn insert(&mut self, k: usize, v: V)
Insert a single pair into the map.
§Panics
It may panic if you attempt to refer to they key that is outside
of the boundary of this map. It will not return None
, it will panic.
However, in “release” mode it will not panic, but will lead to
undefined behavior.
Sourcepub fn get(&self, k: usize) -> Option<&V>
pub fn get(&self, k: usize) -> Option<&V>
Get a reference to a single value.
§Panics
It may panic if you attempt to refer to they key that is outside
of the boundary of this map. It will not return None
, it will panic.
However, in “release” mode it will not panic, but will lead to
undefined behavior.
Sourcepub fn get_mut(&mut self, k: usize) -> Option<&mut V>
pub fn get_mut(&mut self, k: usize) -> Option<&mut V>
Get a mutable reference to a single value.
§Panics
It may panic if you attempt to refer to they key that is outside
of the boundary of this map. It will not return None
, it will panic.
However, in “release” mode it will not panic, but will lead to
undefined behavior.