pub struct IdMap<T> { /* private fields */ }Expand description
A container that gives each item a unique id. Internally all elements are stored contiguously.
Implementations§
Source§impl<T> IdMap<T>
impl<T> IdMap<T>
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Creates an IdMap<T> with the specified capacity.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of id-value pairs the map can hold before reallocating.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Resizes the map to minimize allocated memory.
Sourcepub fn insert(&mut self, val: T) -> Id
pub fn insert(&mut self, val: T) -> Id
Inserts a value into an empty slot in the map and returns its id.
Sourcepub fn insert_at(&mut self, id: Id, val: T) -> Option<T>
pub fn insert_at(&mut self, id: Id, val: T) -> Option<T>
Inserts a value at a specific id, returning the old value if it existed.
Sourcepub fn remove(&mut self, id: Id) -> Option<T>
pub fn remove(&mut self, id: Id) -> Option<T>
Removes an id from the map, returning its value if it was previously in the map.
Sourcepub fn get_or_insert(&mut self, id: Id, val: T) -> &mut T
pub fn get_or_insert(&mut self, id: Id, val: T) -> &mut T
If the id has a value, returns it, otherwise inserts a new value.
Sourcepub fn get_or_insert_with<F: FnOnce() -> T>(&mut self, id: Id, f: F) -> &mut T
pub fn get_or_insert_with<F: FnOnce() -> T>(&mut self, id: Id, f: F) -> &mut T
If the id has a value, returns it, otherwise inserts a new value with the provided closure.
Sourcepub fn remove_set(&mut self, set: &IdSet)
pub fn remove_set(&mut self, set: &IdSet)
Removes all ids in the set from the map.
Sourcepub fn retain<F: FnMut(Id, &T) -> bool>(&mut self, pred: F)
pub fn retain<F: FnMut(Id, &T) -> bool>(&mut self, pred: F)
Remove all values not satisfying the predicate.
Sourcepub fn contains(&self, id: Id) -> bool
pub fn contains(&self, id: Id) -> bool
Returns true if the map contains a value for the specified id.
Sourcepub fn get(&self, id: Id) -> Option<&T>
pub fn get(&self, id: Id) -> Option<&T>
Returns a reference to the value at the specified id if it is in the map.
Sourcepub fn get_mut(&mut self, id: Id) -> Option<&mut T>
pub fn get_mut(&mut self, id: Id) -> Option<&mut T>
Returns a mutable reference to the value at the specified id if it is in the map.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, T> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, T> ⓘ
A mutable iterator over values, in order of increasing id.
Sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
An iterator over id-value pairs, in order of increasing id.
Trait Implementations§
Source§impl<T> Extend<T> for IdMap<T>
impl<T> Extend<T> for IdMap<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)