Struct id_vec::vec::IdVec [−][src]
pub struct IdVec<T> { /* fields omitted */ }
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.
Methods
impl<T> IdVec<T>
[src]
impl<T> IdVec<T>
pub fn new() -> Self
[src]
pub fn new() -> Self
Does not allocate heap memory
pub fn with_capacity(capacity: usize) -> Self
[src]
pub fn with_capacity(capacity: usize) -> Self
pub fn from_vec(elements: Vec<T>) -> Self
[src]
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
[src]
pub fn len(&self) -> usize
pub fn id_index_limit(&self) -> usize
[src]
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
[src]
pub fn capacity(&self) -> usize
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
pub fn contains_id(&self, element: Id<T>) -> bool
[src]
pub fn contains_id(&self, element: Id<T>) -> bool
Excludes deleted elements, and indices out of range
pub fn is_packed(&self) -> bool
[src]
pub fn is_packed(&self) -> bool
Returns if the internal vector does not contain any deleted elements
pub fn remove(&mut self, element: Id<T>)
[src]
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.
pub fn pop(&mut self) -> Option<(Id<T>, T)>
[src]
pub fn pop(&mut self) -> Option<(Id<T>, T)>
Removes an id and the associated element.
See pop_element
for more information.
pub fn pop_element(&mut self) -> Option<T>
[src]
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.
pub fn insert(&mut self, element: T) -> Id<T>
[src]
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.
pub fn get(&self, element: Id<T>) -> Option<&T>
[src]
pub fn get(&self, element: Id<T>) -> Option<&T>
Return a reference to the element that this id points to
pub fn get_mut<'s>(&'s mut self, element: Id<T>) -> Option<&'s mut T>
[src]
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
pub fn swap_elements(&mut self, id1: Id<T>, id2: Id<T>)
[src]
pub fn swap_elements(&mut self, id1: Id<T>, id2: Id<T>)
Swap the elements pointed to. Panic on invalid Id parameter.
pub fn clear(&mut self)
[src]
pub fn clear(&mut self)
Removes all elements, instantly deallocating
pub fn shrink_to_fit(&mut self)
[src]
pub fn shrink_to_fit(&mut self)
Shrinks the internal vector itself
pub fn reserve(&mut self, additional: usize)
[src]
pub fn reserve(&mut self, additional: usize)
Reserve space for more elements, avoiding frequent reallocation
pub fn retain<F>(&mut self, predicate: F) where
F: Fn(Id<T>, &T) -> bool,
[src]
pub fn retain<F>(&mut self, predicate: F) where
F: Fn(Id<T>, &T) -> bool,
Retain only the elements specified by the predicate. May deallocate unused elements.
pub fn pack<F>(&mut self, remap: F) where
F: FnMut(Id<T>, Id<T>),
[src]
pub fn pack<F>(&mut self, remap: F) where
F: FnMut(Id<T>, Id<T>),
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.
ⓘImportant traits for Iter<'s, T>pub fn iter<'s>(&'s self) -> Iter<'s, T>
[src]
pub fn iter<'s>(&'s self) -> Iter<'s, T>
Used for immutable access to ids and elements
ⓘImportant traits for IntoElements<T>pub fn into_elements(self) -> IntoElements<T>
[src]
pub fn into_elements(self) -> IntoElements<T>
Iterate over the elements, consuming this IdVec
ⓘImportant traits for DrainElements<'s, T>pub fn drain_elements(&mut self) -> DrainElements<T>
[src]
pub fn drain_elements(&mut self) -> DrainElements<T>
Iterate over the elements, clearing this IdVec
ⓘImportant traits for ElementIter<'s, T>pub fn elements<'s>(&'s self) -> ElementIter<'s, T>
[src]
pub fn elements<'s>(&'s self) -> ElementIter<'s, T>
Used for immutable direct access to all used elements
ⓘImportant traits for IdIter<'s, T>pub fn ids<'s>(&'s self) -> IdIter<'s, T>
[src]
pub fn ids<'s>(&'s self) -> IdIter<'s, T>
Used for immutable indirect access
ⓘImportant traits for OwnedIdIter<T>pub fn get_ids(&self) -> OwnedIdIter<T>
[src]
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.
pub fn ids_eq(&self, other: &Self) -> bool
[src]
pub fn ids_eq(&self, other: &Self) -> bool
Compares if two id-maps contain the same ids, ignoring elements. Complexity of O(n)
pub fn elements_eq(&self, other: &Self) -> bool where
T: PartialEq,
[src]
pub fn elements_eq(&self, other: &Self) -> bool where
T: PartialEq,
Compares if two id-maps contain the same elements, ignoring ids. Worst case complexity of O(n^2)
pub fn contains_element(&self, element: &T) -> bool where
T: PartialEq,
[src]
pub fn contains_element(&self, element: &T) -> bool where
T: PartialEq,
Worst case complexity of O(n)
pub fn find_id_of_element(&self, element: &T) -> Option<Id<T>> where
T: PartialEq,
[src]
pub fn find_id_of_element(&self, element: &T) -> Option<Id<T>> where
T: PartialEq,
Worst case complexity of O(n)
Trait Implementations
impl<T: Clone> Clone for IdVec<T>
[src]
impl<T: Clone> Clone for IdVec<T>
fn clone(&self) -> IdVec<T>
[src]
fn clone(&self) -> IdVec<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T: Default> Default for IdVec<T>
[src]
impl<T: Default> Default for IdVec<T>
impl<T> FromIterator<T> for IdVec<T>
[src]
impl<T> FromIterator<T> for IdVec<T>
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
[src]
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
impl<T> IntoIterator for IdVec<T>
[src]
impl<T> IntoIterator for IdVec<T>
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoElements<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<T> From<Vec<T>> for IdVec<T>
[src]
impl<T> From<Vec<T>> for IdVec<T>
impl<T> Index<Id<T>> for IdVec<T>
[src]
impl<T> Index<Id<T>> for IdVec<T>
type Output = T
The returned type after indexing.
fn index(&self, element: Id<T>) -> &T
[src]
fn index(&self, element: Id<T>) -> &T
Performs the indexing (container[index]
) operation.
impl<T> IndexMut<Id<T>> for IdVec<T>
[src]
impl<T> IndexMut<Id<T>> for IdVec<T>
fn index_mut(&mut self, element: Id<T>) -> &mut T
[src]
fn index_mut(&mut self, element: Id<T>) -> &mut T
Performs the mutable indexing (container[index]
) operation.
impl<T> Eq for IdVec<T> where
T: Eq,
[src]
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)
impl<T> PartialEq for IdVec<T> where
T: PartialEq,
[src]
impl<T> PartialEq for IdVec<T> where
T: PartialEq,
fn eq(&self, other: &Self) -> bool
[src]
fn eq(&self, other: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<T> Debug for IdVec<T> where
T: Debug,
[src]
impl<T> Debug for IdVec<T> where
T: Debug,