pub struct Vector<T> { /* private fields */ }Expand description
Tiered vector which maintains a collection of circular deques in order to efficiently support insert and remove from any location within the vector.
Implementations§
Source§impl<T> Vector<T>
impl<T> Vector<T>
Sourcepub fn insert(&mut self, index: usize, value: T)
pub fn insert(&mut self, index: usize, value: T)
Inserts an element at position index within the array, shifting some
elements to the right as needed.
Sourcepub fn push_within_capacity(&mut self, value: T) -> Result<(), T>
pub fn push_within_capacity(&mut self, value: T) -> Result<(), T>
Appends an element if there is sufficient spare capacity, otherwise an error is returned with the element.
§Time complexity
O(√N) in the worst case.
Sourcepub fn remove(&mut self, index: usize) -> T
pub fn remove(&mut self, index: usize) -> T
Removes an element from position index within the array, shifting some
elements to the left as needed to close the gap.
§Time complexity
O(√N) in the worst case.
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes the last element from the vector and returns it, or None if the
vector is empty.
§Time complexity
O(√N) in the worst case.
Sourcepub fn pop_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T>
pub fn pop_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T>
Removes and returns the last element from a vector if the predicate
returns true, or None`` if the predicate returns false`` or the vector
is empty (the predicate will not be called in that case).
§Time complexity
O(√N) in the worst case.
pub fn iter(&self) -> VectorIter<'_, T> ⓘ
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total number of elements the vector can hold without reallocating.
§Time complexity
Constant time.