Struct shared_vector::UniqueVector
source · pub struct UniqueVector<T> { /* private fields */ }Expand description
A heap allocated, mutable contiguous buffer containing elements of type T.
Similar in principle to a Vec<T>.
It can be converted for free into an immutable SharedVector<T> or AtomicSharedVector<T>.
Unique and shared vectors expose similar functionality. UniqueVector takes advantage of
the guaranteed uniqueness at the type level to provide overall faster operations than its
shared counterparts, while its memory layout makes it very cheap to convert to a shared vector
(involving not allocation or copy).
Internal representation
UniqueVector stores its length and capacity inline and points to the first element of the
allocated buffer. Room for a 16 bytes header is left before the first element so that the
vector can be converted into a SharedVector or AtomicSharedVector without reallocating
the storage.
Implementations§
source§impl<T> UniqueVector<T>
impl<T> UniqueVector<T>
sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Creates an empty pre-allocated vector with a given storage capacity.
Does not allocate memory if cap is zero.
sourcepub fn try_with_capacity(cap: usize) -> Result<Self, AllocError>
pub fn try_with_capacity(cap: usize) -> Result<Self, AllocError>
Creates an empty pre-allocated vector with a given storage capacity.
Does not allocate memory if cap is zero.
pub fn from_slice(data: &[T]) -> Selfwhere T: Clone,
sourcepub fn from_elem(elem: T, n: usize) -> Selfwhere
T: Clone,
pub fn from_elem(elem: T, n: usize) -> Selfwhere T: Clone,
Creates a vector with n copies of elem.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the vector, also referred to as its ‘length’.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total number of elements the vector can hold without reallocating.
sourcepub fn remaining_capacity(&self) -> usize
pub fn remaining_capacity(&self) -> usize
Returns number of elements that can be added without reallocating.
Make this vector immutable.
This operation is cheap, the underlying storage does not not need to be reallocated.
Make this vector immutable.
This operation is cheap, the underlying storage does not not need to be reallocated.
pub fn as_slice(&self) -> &[T] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [T] ⓘ
pub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn first(&self) -> Option<&T>
pub fn last(&self) -> Option<&T>
pub fn first_mut(&mut self) -> Option<&mut T>
pub fn last_mut(&mut self) -> Option<&mut T>
pub fn push(&mut self, val: T)
pub fn pop(&mut self) -> Option<T>
pub fn push_slice(&mut self, data: &[T])where T: Clone,
pub fn extend(&mut self, data: impl IntoIterator<Item = T>)
pub fn clear(&mut self)
sourcepub fn clone_buffer(&self) -> Selfwhere
T: Clone,
pub fn clone_buffer(&self) -> Selfwhere T: Clone,
Allocate a clone of this buffer.
sourcepub fn clone_buffer_with_capacity(&self, cap: usize) -> Selfwhere
T: Clone,
pub fn clone_buffer_with_capacity(&self, cap: usize) -> Selfwhere T: Clone,
Allocate a clone of this buffer with a different capacity
The capacity must be at least as large as the buffer’s length.