pub struct ExtensibleArray<T> { /* private fields */ }Expand description
Growable array as described by Moffat and Mackenzie.
Implementations§
Source§impl<T> ExtensibleArray<T>
impl<T> ExtensibleArray<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Return an empty extensible array with zero capacity.
Note that pre-allocating capacity has no benefit with this data structure since append operations are always constant time and no reallocation and copy is ever performed.
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
Constant time.
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes the last element from an array and returns it, or None if it
is empty.
§Time complexity
Constant time.
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
Constant time.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total number of elements the extensible array can hold without reallocating.
§Time complexity
log2(count)/2
Sourcepub fn swap_remove(&mut self, index: usize) -> T
pub fn swap_remove(&mut self, index: usize) -> T
Removes an element from the vector and returns it.
The removed element is replaced by the last element of the vector.
This does not preserve ordering of the remaining elements.
§Time complexity
Constant time.
Sourcepub fn iter(&self) -> ExtArrayIter<'_, T> ⓘ
pub fn iter(&self) -> ExtArrayIter<'_, T> ⓘ
Returns an iterator over the extensible array.
The iterator yields all items from start to end.