pub struct IdVec<T> { /* private fields */ }Expand description
Inserting elements into this map yields a persistent, type-safe Index to that new element. It does not try to preserve the order of the inserted items.
The IdVec does not actively try to preserve order of inserted elements, but a packed IdVec will append elements to the end of the internal vector.
Implementations§
Source§impl<T> IdVec<T>
impl<T> IdVec<T>
pub fn with_capacity(capacity: usize) -> Self
Sourcepub fn from_vec(elements: Vec<T>) -> Self
pub fn from_vec(elements: Vec<T>) -> Self
Create a map containing these elements. Directly uses the specified vector, so no heap allocation is made calling this function.
pub fn len(&self) -> usize
Sourcepub fn id_index_limit(&self) -> usize
pub fn id_index_limit(&self) -> usize
Used to estimate the maximal index_value() of all ids inside this IdVec.
This IdVec will not contain an id with an index value greater than or equal to this value.
pub fn capacity(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn contains_id(&self, element: Id<T>) -> bool
pub fn contains_id(&self, element: Id<T>) -> bool
Excludes deleted elements, and indices out of range
Sourcepub fn is_packed(&self) -> bool
pub fn is_packed(&self) -> bool
Returns if the internal vector does not contain any deleted elements
Sourcepub fn remove(&mut self, element: Id<T>)
pub fn remove(&mut self, element: Id<T>)
Enable the specified id to be overwritten when a new element is inserted. This does not directly deallocate the element. Make sure that no ids pointing to that element exist after this call. Ignores invalid and deleted ids.
Sourcepub fn pop(&mut self) -> Option<(Id<T>, T)>
pub fn pop(&mut self) -> Option<(Id<T>, T)>
Removes an id and the associated element.
See pop_element for more information.
Sourcepub fn pop_element(&mut self) -> Option<T>
pub fn pop_element(&mut self) -> Option<T>
Removes an element from this map, returns the element: Removes the one element which is the least work to remove, the one with the highest id. May deallocate unused elements. Returns None if this map is empty.
Sourcepub fn insert(&mut self, element: T) -> Id<T>
pub fn insert(&mut self, element: T) -> Id<T>
Associate the specified element with a currently unused id. This may overwrite (thus drop) unused elements.
Sourcepub fn get(&self, element: Id<T>) -> Option<&T>
pub fn get(&self, element: Id<T>) -> Option<&T>
Return a reference to the element that this id points to
Sourcepub fn get_mut<'s>(&'s mut self, element: Id<T>) -> Option<&'s mut T>
pub fn get_mut<'s>(&'s mut self, element: Id<T>) -> Option<&'s mut T>
Return a mutable reference to the element that this id points to
Sourcepub fn swap_elements(&mut self, id1: Id<T>, id2: Id<T>)
pub fn swap_elements(&mut self, id1: Id<T>, id2: Id<T>)
Swap the elements pointed to. Panic on invalid Id parameter.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the internal vector itself
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserve space for more elements, avoiding frequent reallocation
Sourcepub fn retain<F>(&mut self, predicate: F)
pub fn retain<F>(&mut self, predicate: F)
Retain only the elements specified by the predicate. May deallocate unused elements.
Sourcepub fn pack<F>(&mut self, remap: F)
pub fn pack<F>(&mut self, remap: F)
Make this map have a continuous flow of indices, having no wasted allocation and calling remap(old_id, new_id) for every element that has been moved to a new Id It does not preserve order of the inserted items.
Sourcepub fn into_elements(self) -> IntoElements<T> ⓘ
pub fn into_elements(self) -> IntoElements<T> ⓘ
Iterate over the elements, consuming this IdVec
Sourcepub fn drain_elements(&mut self) -> DrainElements<'_, T> ⓘ
pub fn drain_elements(&mut self) -> DrainElements<'_, T> ⓘ
Iterate over the elements, clearing this IdVec
Sourcepub fn elements<'s>(&'s self) -> ElementIter<'s, T> ⓘ
pub fn elements<'s>(&'s self) -> ElementIter<'s, T> ⓘ
Used for immutable direct access to all used elements
Sourcepub fn get_ids(&self) -> OwnedIdIter<T> ⓘ
pub fn get_ids(&self) -> OwnedIdIter<T> ⓘ
Used for full mutable access, while allowing inserting and deleting while iterating.
The iterator will keep an independent state, in order to un-borrow the underlying map.
This may be more expensive than iter,
because it needs to clone the internal set of unused ids.
Sourcepub fn ids_eq(&self, other: &Self) -> bool
pub fn ids_eq(&self, other: &Self) -> bool
Compares if two id-maps contain the same ids, ignoring elements. Complexity of O(n)
Sourcepub fn elements_eq(&self, other: &Self) -> boolwhere
T: PartialEq,
pub fn elements_eq(&self, other: &Self) -> boolwhere
T: PartialEq,
Compares if two id-maps contain the same elements, ignoring ids. Worst case complexity of O(n^2)
Sourcepub fn contains_element(&self, element: &T) -> boolwhere
T: PartialEq,
pub fn contains_element(&self, element: &T) -> boolwhere
T: PartialEq,
Worst case complexity of O(n)
Trait Implementations§
Source§impl<T> FromIterator<T> for IdVec<T>
impl<T> FromIterator<T> for IdVec<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Source§impl<T> IntoIterator for IdVec<T>
impl<T> IntoIterator for IdVec<T>
impl<T> Eq for IdVec<T>where
T: Eq,
Equality means: The same Ids pointing to the same elements, ignoring deleted elements. Complexity of O(n)