pub struct Vector<T, const N: usize>where
Const<N>: ValidBranchingConstant,{ /* private fields */ }
Expand description
A persistent vector.
Implementations§
Source§impl<T: Clone, const N: usize> Vector<T, N>where
Const<N>: ValidBranchingConstant,
impl<T: Clone, const N: usize> Vector<T, N>where
Const<N>: ValidBranchingConstant,
Sourcepub fn get(&self, idx: usize) -> Option<&T>
pub fn get(&self, idx: usize) -> Option<&T>
Gets an element at a given index, or None
if idx
is out-of-bounds.
Sourcepub fn set(&mut self, idx: usize, elt: T)
pub fn set(&mut self, idx: usize, elt: T)
Sets an element at a given index.
Panics if the index is out of bounds.
Sourcepub fn push(&mut self, elt: T)
pub fn push(&mut self, elt: T)
Adds an element to the end of this array.
Runs in time complexity O(log n)
where n
is the array length.
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes and returns the element at the end of this array, or
None
if we’re empty.
Runs in time complexity O(log self.len())
.
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
If len
is less than our length, shortens this vector to length len
.
If len
is greater than or equal to our length, does nothing.
The running time is O(log self.len() + (len - self.len()))
. That
is, it is linear in the number of elements to be discarded. Even if
the elements to be discarded have trivial destructors, we still need
to destroy (and potentially de-allocate) a linear number of internal
nodes. However, the constant factor in this linear term should be quite
small; you can expect that truncate
is much faster than multiple calls
to pop
.
Sourcepub fn iter(&self) -> Iter<'_, T, N> ⓘ
pub fn iter(&self) -> Iter<'_, T, N> ⓘ
Returns an iterator over all elements in this vector.
Iterator construction runs in O(log self.len())
time. Each step
of the iteration runs in amortized constant time, worst-case O(log self.len())
time.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T, N> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T, N> ⓘ
Returns a mutable iterator over all elements in this vector.
Iterator construction runs in O(log self.len())
time. Each step
of the iteration runs in amortized constant time, worst-case O(log self.len())
time.
Sourcepub fn iter_starting_at(&self, idx: usize) -> Iter<'_, T, N> ⓘ
pub fn iter_starting_at(&self, idx: usize) -> Iter<'_, T, N> ⓘ
Returns an iterator over borrowed elements in this vector, starting at a specific index.
Iterator construction runs in O(log self.len())
time. Each step
of the iteration runs in amortized constant time, worst-case
O(log self.len())
time. In particular, if idx
is large then this is
much more efficient than calling iter
and then advancing past idx
elements.
Sourcepub fn iter_mut_starting_at(&mut self, idx: usize) -> IterMut<'_, T, N> ⓘ
pub fn iter_mut_starting_at(&mut self, idx: usize) -> IterMut<'_, T, N> ⓘ
Returns an iterator over mutable elements in this vector, starting at a specific index.
Iterator construction runs in O(log self.len())
time. Each step
of the iteration runs in amortized constant time, worst-case
O(log self.len())
time. In particular, if idx
is large then this is
much more efficient than calling iter
and then advancing past idx
elements.
Sourcepub fn into_iter_starting_at(self, idx: usize) -> IntoIter<T, N> ⓘ
pub fn into_iter_starting_at(self, idx: usize) -> IntoIter<T, N> ⓘ
Returns an iterator over borrowed elements in this vector, starting at a specific index.
Iterator construction runs in O(log self.len() + idx)
time. Each step
of the iteration runs in amortized constant time, worst-case
O(log self.len())
time. Unlike the borrowed iter_starting_at
, this is
not asymptotically faster than calling into_iter
and then advancing
past idx
elements, because we need to destruct and then potentially
de-allocate a linear (in idx
) number of things. However, this method
should be faster in practice than iterating over idx
elements.
Trait Implementations§
Source§impl<T: Clone, const N: usize> Extend<T> for Vector<T, N>where
Const<N>: ValidBranchingConstant,
impl<T: Clone, const N: usize> Extend<T> for Vector<T, N>where
Const<N>: ValidBranchingConstant,
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
)