Struct orx_split_vec::CustomGrowth
source · pub struct CustomGrowth<T> { /* private fields */ }Expand description
Stategy which allows to define a custom growth rate with a function of priorly created fragments.
Examples
use orx_split_vec::SplitVec;
let mut vec = SplitVec::with_linear_growth(16);
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());
}
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<T> CustomGrowth<T>
impl<T> CustomGrowth<T>
sourcepub fn new(
get_capacity_of_new_fragment: Rc<dyn Fn(&[Fragment<T>]) -> usize>
) -> Self
pub fn new( get_capacity_of_new_fragment: Rc<dyn Fn(&[Fragment<T>]) -> usize> ) -> Self
Creates a new custom growth where the growth strategy is
defined by the function get_capacity_of_new_fragment.
Panics
Panics if the function returns 0 as the capacity of the new fragment
for any given set of already created fragments.
Trait Implementations§
source§impl<T: Clone> Clone for CustomGrowth<T>
impl<T: Clone> Clone for CustomGrowth<T>
source§fn clone(&self) -> CustomGrowth<T>
fn clone(&self) -> CustomGrowth<T>
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<T> Debug for CustomGrowth<T>
impl<T> Debug for CustomGrowth<T>
source§impl<T: 'static> Default for CustomGrowth<T>
impl<T: 'static> Default for CustomGrowth<T>
source§fn default() -> Self
fn default() -> Self
Creates the default custom growth which doubles the initial capacity every 4 fragments.
Let c be the initial capacity of the split vector; i.e., capacity of the first fragment. Then, fragment capacities with the default function will be computed as:
- capacities of fragments 0..4 = c
- capacities of fragments 4..8 = 2c
- capacities of fragments 8..12 = 3c
- …
source§impl<T> SplitVecGrowth<T> for CustomGrowth<T>
impl<T> SplitVecGrowth<T> for CustomGrowth<T>
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.Auto Trait Implementations§
impl<T> !RefUnwindSafe for CustomGrowth<T>
impl<T> !Send for CustomGrowth<T>
impl<T> !Sync for CustomGrowth<T>
impl<T> Unpin for CustomGrowth<T>
impl<T> !UnwindSafe for CustomGrowth<T>
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