Struct AtomicLazyVec

Source
pub struct AtomicLazyVec<T: Clone> { /* private fields */ }
Expand description

lazy-cogs implementation of a Vector. Similar to Vector but thread-safe. It’s a collection meant to be used when you need to work with the individual elements

Cloning a AtomicLazyVec 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> AtomicLazyVec<T>

Source

pub fn new() -> Self

Creates a new empty AtomicLazyVec

Source

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)

Source

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

Source

pub fn get_lazy(&self, index: usize) -> Option<Alc<T>>

Obtains an atomic lazy clone to a specific value in the lazy vector

If the index is out of range it returns None

Source

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)
Source

pub fn push(&mut self, value: T)

Pushes a new element at the end of the vector

Source

pub fn pop(&mut self) -> Option<T>

Pops an element at the end of the vector

Source

pub fn remove(&mut self, index: usize) -> T

Removes an element from the vector

Source

pub fn remove_lazy(&mut self, index: usize) -> Alc<T>

Removes an element from the vector and returns a lazy clone to it

Source

pub fn insert(&mut self, index: usize, value: T)

Inserts an element at a given position in a vector

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Produces an iterator over the elements

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>

Produces a mutable iterator

Trait Implementations§

Source§

impl<T: Debug + Clone> Debug for AtomicLazyVec<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Clone> From<&[T]> for AtomicLazyVec<T>

Source§

fn from(value: &[T]) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone> From<Vec<Alc<T>>> for AtomicLazyVec<T>

Source§

fn from(value: Vec<Alc<T>>) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone> From<Vec<T>> for AtomicLazyVec<T>

Source§

fn from(value: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone> FromIterator<T> for AtomicLazyVec<T>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: Clone> Index<usize> for AtomicLazyVec<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: Clone> IndexMut<usize> for AtomicLazyVec<T>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: Clone> Into<Vec<Alc<T>>> for AtomicLazyVec<T>

Source§

fn into(self) -> Vec<Alc<T>>

Converts this type into the (usually inferred) input type.
Source§

impl<T: Clone> Into<Vec<T>> for AtomicLazyVec<T>

Source§

fn into(self) -> Vec<T>

Converts this type into the (usually inferred) input type.
Source§

impl<T: Clone> IntoIterator for AtomicLazyVec<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: Clone> LazyClone for AtomicLazyVec<T>

Source§

fn lazy(&self) -> Self

The O(1) lazy-clone method. Useful for cloning data that doesn’t necessarily need to be mutated.
Source§

fn eager(&self) -> Self

A non-lazy cloning method. Useful for cloning data that is known to modified
Source§

fn is_mutable(&self) -> bool

Checks if the structure can be mutated with no side effects

Auto Trait Implementations§

§

impl<T> Freeze for AtomicLazyVec<T>

§

impl<T> RefUnwindSafe for AtomicLazyVec<T>
where T: RefUnwindSafe,

§

impl<T> Send for AtomicLazyVec<T>
where T: Sync + Send,

§

impl<T> Sync for AtomicLazyVec<T>
where T: Sync + Send,

§

impl<T> Unpin for AtomicLazyVec<T>

§

impl<T> UnwindSafe for AtomicLazyVec<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.