Struct AtomicLazyList

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

lazy-cogs implementation of a AtomicLinkedList. Similar to LazyList but thread-safe. It’s a collection meant to be used when you need to work with the whole data, not it’s elements

Cloning a AtomicLazyList is always O(1). Modifing or getting piecies of data is O(n). Actually, pushing and popping into/from the front or back of the list may be O(1) is the list is mutable

Implementations§

Source§

impl<T: Clone> AtomicLazyList<T>

Source

pub fn new() -> Self

Creates a new empty LazyList

Source

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

Obtains a reference to a specific value in the list

If the index is out of range it returns None

This operation is always O(n)

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Obtains a mutable reference to a specific value in the list

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 a lazy clone to a specific value in the list

Source

pub fn set(&mut self, index: usize, value: T) -> Result<(), ()>

Changes the value at a given position of the list

Returns Ok(()) if the index is in-bounds and Err(()) if not

Source

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

Pushes a new element at the end of the list

Source

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

Pushes a new element at the beginning of the list

Source

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

Pops an element from the end of the list and returns the lazy clone to the value

Source

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

Pops an element from the beginning of the list and returns the lazy clone to the value

Source

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

Pops an element from the end of the list and returns the lazy clone to the value

Source

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

Pops an element from the beginning of the list and returns the lazy clone to the value

Source

pub fn front(&self) -> Option<&T>

Returns a reference to the first element of the list

Return None if the list is empty

Source

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

Returns a mutable reference to the first element of the list

Return None if the list is empty

This operation is protected, it means, that the other clones aren’t affected

Source

pub fn front_lazy(&self) -> Option<Alc<T>>

Returns a lazy clone to the first element of the list

Returns None if the list is empty

Source

pub fn back(&self) -> Option<&T>

Returns a reference to the last element of the list

Return None if the list is empty

Source

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

Returns a mutable reference to the last element of the list

Return None if the list is empty

This operation is protected, it means, that the other clones aren’t affected

Source

pub fn back_lazy(&self) -> Option<Alc<T>>

Returns a lazy clone to the last element of the list

Returns None if the list is empty

Source

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

Produces an iterator over the elements of the list

Source

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

Produces a mutable iterator over the elements of the list

Trait Implementations§

Source§

impl<T: Debug + Clone> Debug for AtomicLazyList<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 AtomicLazyList<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T: Clone> From<LinkedList<Alc<T>>> for AtomicLazyList<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T: Clone> From<LinkedList<T>> for AtomicLazyList<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T: Clone> From<Vec<Alc<T>>> for AtomicLazyList<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 AtomicLazyList<T>

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Creates a value from an iterator. Read more
Source§

impl<T: Clone> Into<LinkedList<Alc<T>>> for AtomicLazyList<T>

Source§

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

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

impl<T: Clone> Into<LinkedList<T>> for AtomicLazyList<T>

Source§

fn into(self) -> LinkedList<T>

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

impl<T: Clone> IntoIterator for AtomicLazyList<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 AtomicLazyList<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 AtomicLazyList<T>

§

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

§

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

§

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

§

impl<T> Unpin for AtomicLazyList<T>

§

impl<T> UnwindSafe for AtomicLazyList<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.