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 Growth for Linear
impl Growth for Linear
source§unsafe fn get_ptr_mut<T>(
&self,
fragments: &mut [Fragment<T>],
index: usize
) -> Option<*mut T>
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
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)>
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 moresource§fn maximum_concurrent_capacity<T>(
&self,
fragments: &[Fragment<T>],
fragments_capacity: usize
) -> usize
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>
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 moresource§impl GrowthWithConstantTimeAccess for Linear
impl GrowthWithConstantTimeAccess for Linear
source§impl PartialEq for Linear
impl PartialEq for Linear
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more