Struct orx_concurrent_vec::Linear

source ·
pub struct Linear { /* private fields */ }
Expand description

Strategy which allows the split vector to grow linearly.

In other words, each new fragment will have equal capacity, which is equal to the capacity of the first fragment.

§Examples

use orx_split_vec::*;

// SplitVec<usize, Linear>
let mut vec = SplitVec::with_linear_growth(4);

assert_eq!(1, vec.fragments().len());
assert_eq!(Some(16), vec.fragments().first().map(|f| f.capacity()));
assert_eq!(Some(0), vec.fragments().first().map(|f| f.len()));

// push 160 elements
for i in 0..10 * 16 {
    vec.push(i);
}

assert_eq!(10, vec.fragments().len());
for fragment in vec.fragments() {
    assert_eq!(16, fragment.len());
    assert_eq!(16, fragment.capacity());
}

// push the 161-st element
vec.push(42);
assert_eq!(11, vec.fragments().len());
assert_eq!(Some(16), vec.fragments().last().map(|f| f.capacity()));
assert_eq!(Some(1), vec.fragments().last().map(|f| f.len()));

Trait Implementations§

source§

impl Clone for Linear

source§

fn clone(&self) -> Linear

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Linear

source§

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

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

impl Growth for Linear

source§

unsafe fn get_ptr_mut<T>( &self, fragments: &mut [Fragment<T>], index: usize ) -> Option<*mut T>

O(1) Returns a mutable reference to the index-th element of the split vector of the fragments.

Returns None if index-th position does not belong to the split vector; i.e., if index is out of cumulative capacity of fragments.

§Safety

This method allows to write to a memory which is greater than the split vector’s length. On the other hand, it will never return a pointer to a memory location that the vector does not own.

source§

fn new_fragment_capacity<T>(&self, _fragments: &[Fragment<T>]) -> usize

Given that the split vector contains the given fragments, returns the capacity of the next fragment.
source§

fn get_fragment_and_inner_indices<T>( &self, vec_len: usize, _fragments: &[Fragment<T>], element_index: usize ) -> Option<(usize, usize)>

O(fragments.len()) Returns the location of the element with the given element_index on the split vector as a tuple of (fragment-index, index-within-fragment). Read more
source§

fn maximum_concurrent_capacity<T>( &self, fragments: &[Fragment<T>], fragments_capacity: usize ) -> usize

Returns the maximum number of elements that can safely be stored in a concurrent program. Read more
source§

fn required_fragments_len<T>( &self, _: &[Fragment<T>], maximum_capacity: usize ) -> Result<usize, String>

Returns the number of fragments with this growth strategy in order to be able to reach a capacity of maximum_capacity of elements. Returns the error if it the growth strategy does not allow the required number of fragments. Read more
source§

impl GrowthWithConstantTimeAccess for Linear

source§

fn get_fragment_and_inner_indices_unchecked( &self, element_index: usize ) -> (usize, usize)

O(1) Returns the location of the element with the given element_index on the split vector as a tuple of (fragment-index, index-within-fragment). Read more
source§

unsafe fn get_ptr_mut<T>( &self, fragments: &mut [Fragment<T>], index: usize ) -> Option<*mut T>

O(1) Returns a mutable reference to the index-th element of the split vector of the fragments. Read more
source§

impl PartialEq for Linear

source§

fn eq(&self, other: &Linear) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Linear

Auto Trait Implementations§

§

impl Freeze for Linear

§

impl RefUnwindSafe for Linear

§

impl Send for Linear

§

impl Sync for Linear

§

impl Unpin for Linear

§

impl UnwindSafe for Linear

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.