Struct orx_split_vec::LinearGrowth
source · pub struct LinearGrowth;
Expand description
Stategy which allows the split vector to grow linearly.
In other words, each new fragment will have equal capacity, which is equal to the capacity of the first fragment.
Examples
use orx_split_vec::prelude::*;
// SplitVec<usize, LinearGrowth>
let mut vec = SplitVec::with_linear_growth(16);
assert_eq!(1, vec.fragments().len());
assert_eq!(Some(16), vec.fragments().first().map(|f| f.capacity()));
assert_eq!(Some(0), vec.fragments().first().map(|f| f.len()));
// push 160 elements
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());
}
// push the 161-st element
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()));
Trait Implementations§
source§impl Clone for LinearGrowth
impl Clone for LinearGrowth
source§fn clone(&self) -> LinearGrowth
fn clone(&self) -> LinearGrowth
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 LinearGrowth
impl Debug for LinearGrowth
source§impl Default for LinearGrowth
impl Default for LinearGrowth
source§fn default() -> LinearGrowth
fn default() -> LinearGrowth
Returns the “default value” for a type. Read more
source§impl PartialEq<LinearGrowth> for LinearGrowth
impl PartialEq<LinearGrowth> for LinearGrowth
source§fn eq(&self, other: &LinearGrowth) -> bool
fn eq(&self, other: &LinearGrowth) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl<T> SplitVecGrowth<T> for LinearGrowth
impl<T> SplitVecGrowth<T> for LinearGrowth
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 LinearGrowth
Auto Trait Implementations§
impl RefUnwindSafe for LinearGrowth
impl Send for LinearGrowth
impl Sync for LinearGrowth
impl Unpin for LinearGrowth
impl UnwindSafe for LinearGrowth
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