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§
Source§impl Linear
impl Linear
Sourcepub fn new(constant_fragment_capacity_exponent: usize) -> Self
pub fn new(constant_fragment_capacity_exponent: usize) -> Self
Creates a linear growth where each fragment will have a capacity of 2 ^ constant_fragment_capacity_exponent
.
§Panics
Panics if constant_fragment_capacity_exponent
is zero or constant_fragment_capacity_exponent >= MAX_EXPONENT
where MAX_EXPONENT
is:
- 29 in 32-bit targets,
- 32 in 64-bit.
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 maximum_concurrent_capacity_bound<T>(
&self,
_: &[Fragment<T>],
_: usize,
) -> usize
fn maximum_concurrent_capacity_bound<T>( &self, _: &[Fragment<T>], _: usize, ) -> usize
Source§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 JaggedIndexer for Linear
impl JaggedIndexer for Linear
Source§unsafe fn jagged_index_unchecked<'a, T: 'a>(
&self,
_: &impl Slices<'a, T>,
flat_index: usize,
) -> JaggedIndex
unsafe fn jagged_index_unchecked<'a, T: 'a>( &self, _: &impl Slices<'a, T>, flat_index: usize, ) -> JaggedIndex
flat_index
-th position if the raw jagged array
defined by the arrays
collection would have been flattened. Read moreSource§unsafe fn jagged_index_unchecked_from_slice<'a, T: 'a>(
&self,
_: &[impl AsRawSlice<T>],
flat_index: usize,
) -> JaggedIndex
unsafe fn jagged_index_unchecked_from_slice<'a, T: 'a>( &self, _: &[impl AsRawSlice<T>], flat_index: usize, ) -> JaggedIndex
flat_index
-th position if the raw jagged array
defined by the arrays
collection would have been flattened. 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 more