pub struct InsertionSet<T> { /* private fields */ }
Expand description
A set of pending insertions on a Vec
When multiple insertions at a
See module documentation for an overview.
Implementations§
Source§impl<T> InsertionSet<T>
impl<T> InsertionSet<T>
Sourcepub fn push(&mut self, insertion: Insertion<T>)
pub fn push(&mut self, insertion: Insertion<T>)
Queue the specified insertion
If there are multiple insertions at the same index, they will be applied in the order queued.
Sourcepub fn insert(&mut self, index: usize, element: T)
pub fn insert(&mut self, index: usize, element: T)
Insert the element to be inserted before the given index
If multiple elements are queued to be inserted at the same index, they will be applied in the original order queued.
Sourcepub fn applied(self, target: Vec<T>) -> Vec<T>
pub fn applied(self, target: Vec<T>) -> Vec<T>
Apply all of the pending insertions against the specified vector, returning the result
Sourcepub fn desired_insertions(&self) -> usize
pub fn desired_insertions(&self) -> usize
The number of insertions that are currently queued
Sourcepub fn list_updated_locations(
&mut self,
target: &[T],
) -> Vec<(OriginalLocation, usize)>
pub fn list_updated_locations( &mut self, target: &[T], ) -> Vec<(OriginalLocation, usize)>
List the updated locations of all the elements (both original and newly inserted).
See Self::compute_updated_locations for details
Sourcepub fn compute_updated_locations<F>(&mut self, target: &[T], func: F)
pub fn compute_updated_locations<F>(&mut self, target: &[T], func: F)
Compute the updated locations of all the elements (both original and newly inserted).
Assumes this set of insertions are being applied against the specified slice, invoking the callback on each element (even if the location is unchanged).
If any of the insertion indexes are out of bounds of the original vec, then this function will panic.
Sourcepub fn apply(&mut self, target: &mut Vec<T>)
pub fn apply(&mut self, target: &mut Vec<T>)
Applies all the insertions to the specified target vector.
This reuses the Vector’s existing memory if possible, but may require a reallocation (due to new values)
The average runtime of this function is O(n + m)
,
where n
is the number of existing elements and m
is the number of insertions.
The worst case running time is O((k * log(k))
where k = n + m
.