Struct orx_split_vec::Doubling
source · pub struct Doubling;
Expand description
Strategy which allows creates a fragment with double the capacity of the prior fragment every time the split vector needs to expand.
Assuming it is the common case compared to empty vector scenarios,
it immediately allocates the first fragment to keep the SplitVec
struct smaller.
§Examples
use orx_split_vec::*;
// SplitVec<usize, Doubling>
let mut vec = SplitVec::with_doubling_growth();
assert_eq!(1, vec.fragments().len());
assert_eq!(Some(4), vec.fragments().first().map(|f| f.capacity()));
assert_eq!(Some(0), vec.fragments().first().map(|f| f.len()));
// fill the first 5 fragments
let expected_fragment_capacities = vec![4, 8, 16, 32];
let num_items: usize = expected_fragment_capacities.iter().sum();
for i in 0..num_items {
vec.push(i);
}
assert_eq!(
expected_fragment_capacities,
vec.fragments()
.iter()
.map(|f| f.capacity())
.collect::<Vec<_>>()
);
assert_eq!(
expected_fragment_capacities,
vec.fragments().iter().map(|f| f.len()).collect::<Vec<_>>()
);
// create the 6-th fragment doubling the capacity
vec.push(42);
assert_eq!(
vec.fragments().len(),
expected_fragment_capacities.len() + 1
);
assert_eq!(vec.fragments().last().map(|f| f.capacity()), Some(32 * 2));
assert_eq!(vec.fragments().last().map(|f| f.len()), Some(1));
Trait Implementations§
source§impl Growth for Doubling
impl Growth for Doubling
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 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.
This method is relevant and useful for concurrent programs, which helps in avoiding the fragments to allocate.
§Panics
Panics if maximum_capacity
is greater than sum { 2^f | for f in 2..34 }.
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 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 Doubling
impl GrowthWithConstantTimeAccess for Doubling
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, fragment_index: usize) -> usize
fn fragment_capacity_of(&self, fragment_index: 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 Doubling
impl PseudoDefault for Doubling
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 Doubling
Auto Trait Implementations§
impl Freeze for Doubling
impl RefUnwindSafe for Doubling
impl Send for Doubling
impl Sync for Doubling
impl Unpin for Doubling
impl UnwindSafe for Doubling
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
)