[][src]Struct dycovec::DycoVec

pub struct DycoVec<T> { /* fields omitted */ }

A dynamically-allocated, concurrent vector.

DycoVecs are thread-safe vectors that support random access, iteration, and tail pushing in an O(1), wait-free* manner, and that's it! It's possible, given &mut self, to clear self and mutate elements, but to do so without &mut self requires wrapping T in a type such as Mutex.

Technical Details

The technical details of DycoVecs are something you're likely to find boring and uninteresting. Read below if you wish, but beware!

Memory Use

Storage is allocated in lazily-allocated individually-contiguous chunks. This means that, given a first chunk capacity of n, pushing less than n (but at least one) elements uses the same memory as pushing n elements, while pushing n + 1 elements makes the DycoVec now have two segments: the first chunk, and a larger second chunk.

Almost Wait-free

The DycoVec is almost always wait-free to push on to, and is otherwise still lock-free. The only exception to wait-freedom is when a segment has filled and a new one is being allocated. This will result in every thread simultaneously attempting to enter a specific critical section. The first to do so will allocate the segment. After finishing, all other threads vying for the lock will enter the critical section as appropriate, notice the segment is already allocated, and immediately unlock. So, the maximum hold-up will be O(n) (n being the number of threads). But, as a reminder, this whole parade only happens when the DycoVec has yet to be allocated.

The only other time the lock is locked is during cloning as to prevent an incomplete allocation from providing bad data for the clone.

Implementations

impl<T> DycoVec<T>[src]

pub fn new() -> Self[src]

Create a new DycoVec with zero length.

The DycoVec will no allocate memory until elements are pushed onto it.

pub fn from_boxed_slice(s: Box<[T]>) -> Self[src]

Create a new DycoVec from a boxed slice.

pub unsafe fn get_unchecked(&self, index: usize) -> &T[src]

Index self by index

pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T[src]

Mutably index self by index

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

Index self by index

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

Mutably index self by index

pub fn clear(&mut self)[src]

Clear all elements in self.

Drops all elements stored in self without losing the allocated space.

pub fn push(&self, t: T) -> usize[src]

Push an element to the end of self and return the new index.

pub fn len(&self) -> usize[src]

Get the number of elements in self.

pub fn is_empty(&self) -> bool[src]

Returns true if the DycoVec contains no elements.

pub const fn iter(&self) -> Iter<'_, T>

Notable traits for Iter<'a, T>

impl<'a, T: 'a> Iterator for Iter<'a, T> type Item = &'a T;
[src]

Create an immutable iterator over the elements of self.

pub fn into_vec(self) -> Vec<T>[src]

Consumes the DycoVec, returning a Vec containing the elements.

Trait Implementations

impl<T: Clone> Clone for DycoVec<T>[src]

impl<T: Debug> Debug for DycoVec<T>[src]

impl<T> Default for DycoVec<T>[src]

impl<T: Eq> Eq for DycoVec<T>[src]

impl<T> Extend<T> for DycoVec<T>[src]

impl<'a, T: 'a> From<&'a DycoVec<T>> for Vec<&'a T>[src]

impl<T> From<DycoVec<T>> for Vec<T>[src]

impl<T> FromIterator<T> for DycoVec<T>[src]

impl<T: Hash> Hash for DycoVec<T>[src]

impl<T> Index<usize> for DycoVec<T>[src]

type Output = T

The returned type after indexing.

impl<T> IndexMut<usize> for DycoVec<T>[src]

impl<T> IntoIterator for DycoVec<T>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

impl<'a, T: 'a> IntoIterator for &'a DycoVec<T>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<T: Ord> Ord for DycoVec<T>[src]

impl<T: PartialEq> PartialEq<DycoVec<T>> for DycoVec<T>[src]

impl<T: PartialOrd> PartialOrd<DycoVec<T>> for DycoVec<T>[src]

Auto Trait Implementations

impl<T> Send for DycoVec<T>

impl<T> Sync for DycoVec<T>

impl<T> Unpin for DycoVec<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.