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>

source

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>

source§

fn clone(&self) -> CustomGrowth<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for CustomGrowth<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: 'static> Default for CustomGrowth<T>

source§

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>

source§

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.
source§

fn get_fragment_and_inner_indices( &self, fragments: &[Fragment<T>], element_index: usize ) -> Option<(usize, usize)>

Returns the location of the element with the given element_index on the split vector as a tuple of (fragment-index, index-within-fragment). Read more

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.