Struct orx_split_vec::DoublingGrowth
source · pub struct DoublingGrowth;Expand description
Stategy 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::prelude::*;
// SplitVec<usize, DoublingGrowth>
let mut vec = SplitVec::with_doubling_growth(2);
assert_eq!(1, vec.fragments().len());
assert_eq!(Some(2), 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![2, 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 Clone for DoublingGrowth
impl Clone for DoublingGrowth
source§fn clone(&self) -> DoublingGrowth
fn clone(&self) -> DoublingGrowth
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for DoublingGrowth
impl Debug for DoublingGrowth
source§impl Default for DoublingGrowth
impl Default for DoublingGrowth
source§fn default() -> DoublingGrowth
fn default() -> DoublingGrowth
Returns the “default value” for a type. Read more
source§impl PartialEq<DoublingGrowth> for DoublingGrowth
impl PartialEq<DoublingGrowth> for DoublingGrowth
source§fn eq(&self, other: &DoublingGrowth) -> bool
fn eq(&self, other: &DoublingGrowth) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl<T> SplitVecGrowth<T> for DoublingGrowth
impl<T> SplitVecGrowth<T> for DoublingGrowth
source§fn new_fragment_capacity(&self, fragments: &[Fragment<T>]) -> usize
fn new_fragment_capacity(&self, fragments: &[Fragment<T>]) -> usize
Given that the split vector contains the given
fragments,
returns the capacity of the next fragment.impl StructuralPartialEq for DoublingGrowth
Auto Trait Implementations§
impl RefUnwindSafe for DoublingGrowth
impl Send for DoublingGrowth
impl Sync for DoublingGrowth
impl Unpin for DoublingGrowth
impl UnwindSafe for DoublingGrowth
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