[−][src]Struct dycovec::DycoVec
A dynamically-allocated, concurrent vector.
DycoVec
s 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 DycoVec
s 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]
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>ⓘ
[src]
Create an immutable iterator over the elements of self
.
pub fn into_vec(self) -> Vec<T>
[src]
Trait Implementations
impl<T: Clone> Clone for DycoVec<T>
[src]
pub fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
[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]
pub fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
[src]
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[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]
pub fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
[src]
impl<T: Hash> Hash for DycoVec<T>
[src]
pub fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> Index<usize> for DycoVec<T>
[src]
type Output = T
The returned type after indexing.
pub fn index(&self, index: usize) -> &Self::Output
[src]
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?
pub fn into_iter(self) -> Self::IntoIter
[src]
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?
pub fn into_iter(self) -> Self::IntoIter
[src]
impl<T: Ord> Ord for DycoVec<T>
[src]
pub fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T: PartialEq> PartialEq<DycoVec<T>> for DycoVec<T>
[src]
pub fn eq(&self, other: &Self) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T: PartialOrd> PartialOrd<DycoVec<T>> for DycoVec<T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,