Struct orx_split_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()));
Implementations§
Trait Implementations§
source§impl Growth for Linear
impl Growth for Linear
source§fn get_ptr<T>(
&self,
fragments: &[Fragment<T>],
index: usize,
) -> Option<*const T>
fn get_ptr<T>( &self, fragments: &[Fragment<T>], index: usize, ) -> Option<*const T>
O(1) Returns a pointer 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 get_ptr_mut<T>(
&self,
fragments: &mut [Fragment<T>],
index: usize,
) -> Option<*mut T>
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 get_ptr_mut_and_indices<T>(
&self,
fragments: &mut [Fragment<T>],
index: usize,
) -> Option<(*mut T, usize, usize)>
fn get_ptr_mut_and_indices<T>( &self, fragments: &mut [Fragment<T>], index: usize, ) -> Option<(*mut T, usize, usize)>
O(1) Returns a mutable reference to the index
-th element of the split vector of the fragments
together with the index of the fragment that the element belongs to
and index of the element withing the respective fragment.
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_from(
&self,
_fragment_capacities: impl ExactSizeIterator<Item = usize>,
) -> usize
fn new_fragment_capacity_from( &self, _fragment_capacities: impl ExactSizeIterator<Item = usize>, ) -> usize
fragment_capacities
,
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)>
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
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>
maximum_capacity
of elements.
Returns the error if it the growth strategy does not allow the required number of fragments. Read moresource§fn first_fragment_capacity(&self) -> usize
fn first_fragment_capacity(&self) -> usize
source§fn new_fragment_capacity<T>(&self, fragments: &[Fragment<T>]) -> usize
fn new_fragment_capacity<T>(&self, fragments: &[Fragment<T>]) -> usize
fragments
,
returns the capacity of the next fragment.source§fn get_ptr_and_indices<T>(
&self,
fragments: &[Fragment<T>],
index: usize,
) -> Option<(*const T, usize, usize)>
fn get_ptr_and_indices<T>( &self, fragments: &[Fragment<T>], index: usize, ) -> Option<(*const T, usize, usize)>
index
-th element of the split vector of the fragments
together with the index of the fragment that the element belongs to
and index of the element withing the respective fragment. Read moresource§impl GrowthWithConstantTimeAccess for Linear
impl GrowthWithConstantTimeAccess for Linear
source§fn get_fragment_and_inner_indices_unchecked(
&self,
element_index: usize,
) -> (usize, usize)
fn get_fragment_and_inner_indices_unchecked( &self, element_index: usize, ) -> (usize, usize)
element_index
on the split vector as a tuple of (fragment-index, index-within-fragment). Read moresource§fn fragment_capacity_of(&self, _: usize) -> usize
fn fragment_capacity_of(&self, _: usize) -> usize
fragment_index
.source§fn get_ptr_mut<T>(
&self,
fragments: &mut [Fragment<T>],
index: usize,
) -> Option<*mut T>
fn get_ptr_mut<T>( &self, fragments: &mut [Fragment<T>], index: usize, ) -> Option<*mut T>
index
-th element of the split vector of the fragments
. Read moresource§fn get_ptr_mut_and_indices<T>(
&self,
fragments: &mut [Fragment<T>],
index: usize,
) -> Option<(*mut T, usize, usize)>
fn get_ptr_mut_and_indices<T>( &self, fragments: &mut [Fragment<T>], index: usize, ) -> Option<(*mut T, usize, usize)>
index
-th element of the split vector of the fragments
together with the index of the fragment that the element belongs to
and index of the element withing the respective fragment. Read moresource§impl PseudoDefault for Linear
impl PseudoDefault for Linear
source§fn pseudo_default() -> Self
fn pseudo_default() -> Self
PseudoDefault
trait allows to create a cheap default instance of a type, which does not claim to be useful. Read moreimpl 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)