pub struct LazyVec<T: Clone> { /* private fields */ }
Expand description
lazy-cogs implementation of a Vector. It’s a collection meant to be used when you need to work with the individual elements
Cloning a LazyVec is always O(1). Getting elements from it is also O(1)
Modifing existing elements may take O(n) if the vector is a clone that is still modified, or if it has living clones.
Pushing elements follow the same logic
Implementations§
Source§impl<T: Clone> LazyVec<T>
impl<T: Clone> LazyVec<T>
Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Obtains a reference to a specific value in the lazy vector
If the index is out of range it returns None
This operation is always O(1)
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
Obtains a mutable reference to a specific value in the lazy vector
If the index is out of range it returns None
This operation is protected, it means, that the other clones aren’t affected
Sourcepub fn get_lazy(&self, index: usize) -> Option<Lc<T>>
pub fn get_lazy(&self, index: usize) -> Option<Lc<T>>
Obtains a lazy clone to a specific value in the lazy vector
If the index is out of range it returns None
Sourcepub fn set(&mut self, index: usize, value: T) -> Result<(), ()>
pub fn set(&mut self, index: usize, value: T) -> Result<(), ()>
Updates an item in the current vector
The operation coast dependents on the state of the vector:
- If vector was never modified, this costs O(n)
- If it was modified but some one cloned it, it’s also O(n)
- If it was modified and no one cloned it, it’s O(1)
- If it isn’t cloned from other vector and no one cloned it, it’s O(1)
Sourcepub fn remove_lazy(&mut self, index: usize) -> Lc<T>
pub fn remove_lazy(&mut self, index: usize) -> Lc<T>
Removes an element from the vector and returns a lazy clone to it