Struct orx_linked_list::CustomGrowth
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::prelude::*;
use std::rc::Rc;
// vec: SplitVec<usize, CustomGrowth<usize>>
let mut vec =
SplitVec::with_custom_growth_function(Rc::new(|fragments: &[Fragment<_>]| {
if fragments.len() % 2 == 0 {
2
} else {
8
}
}));
for i in 0..100 {
vec.push(i);
}
vec.into_iter().zip(0..100).all(|(l, r)| *l == r);
for (f, fragment) in vec.fragments().iter().enumerate() {
if f % 2 == 0 {
assert_eq!(2, fragment.capacity());
} else {
assert_eq!(8, fragment.capacity());
}
}Implementations§
§impl<T> CustomGrowth<T>
impl<T> CustomGrowth<T>
pub fn new(
get_capacity_of_new_fragment: Rc<dyn Fn(&[Fragment<T>]) -> usize, Global>
) -> CustomGrowth<T>
pub fn new( get_capacity_of_new_fragment: Rc<dyn Fn(&[Fragment<T>]) -> usize, Global> ) -> CustomGrowth<T>
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§
§impl<T> Clone for CustomGrowth<T>
impl<T> Clone for CustomGrowth<T>
§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 more§impl<T> Debug for CustomGrowth<T>
impl<T> Debug for CustomGrowth<T>
§impl<T> Default for CustomGrowth<T>where
T: 'static,
impl<T> Default for CustomGrowth<T>where T: 'static,
§fn default() -> CustomGrowth<T>
fn default() -> CustomGrowth<T>
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
- …
§impl<T> SplitVecGrowth<T> for CustomGrowth<T>
impl<T> SplitVecGrowth<T> for CustomGrowth<T>
§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