Struct orx_imp_vec::prelude::Recursive
source ยท pub struct Recursive;Expand description
Equivalent to Doubling strategy except for the following:
- enables zero-cost (no-ops)
appendoperation:- we can append standard vectors, vectors of vectors, split vectors, etc., any data that implements
IntoFragmentstrait, - by simply accepting it as a whole fragment,
- according to benchmarks documented in the crate definition:
SplitVec<_, Recursive>is infinitely faster than other growth strategies or standard vector :)- since its time complexity is independent of size of the data to be appended.
- we can append standard vectors, vectors of vectors, split vectors, etc., any data that implements
- at the expense of providing slower random-access performance:
- random access time complexity of
Doublingstrategy is constant time; - that of
Recursivestrategy is linear in the number of fragments; - according to benchmarks documented in the crate definition:
SplitVec<_, Doubling>or standard vector are around 4 to 7 times faster thanSplitVec<_, Recursive>,- and 1.5 times faster when the elements get very large (16 x
u64).
- random access time complexity of
Note that other operations such as serial access are equivalent to Doubling strategy.
ยงExamples
use orx_split_vec::prelude::*;
// SplitVec<usize, Recursive>
let mut vec = SplitVec::with_recursive_growth();
vec.push('a');
assert_eq!(vec, &['a']);
vec.append(vec!['b', 'c']);
assert_eq!(vec, &['a', 'b', 'c']);
vec.append(vec![vec!['d'], vec!['e', 'f']]);
assert_eq!(vec, &['a', 'b', 'c', 'd', 'e', 'f']);
let other_split_vec: SplitVec<_> = vec!['g', 'h'].into();
vec.append(other_split_vec);
assert_eq!(vec, &['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);Trait Implementationsยง
sourceยงimpl Growth for Recursive
impl Growth for Recursive
sourceยงfn new_fragment_capacity<T>(&self, fragments: &[Fragment<T>]) -> usize
fn new_fragment_capacity<T>(&self, fragments: &[Fragment<T>]) -> usize
Given that the split vector contains the given
fragments,
returns the capacity of the next fragment.sourceยงimpl PartialEq for Recursive
impl PartialEq for Recursive
impl StructuralPartialEq for Recursive
Auto Trait Implementationsยง
impl RefUnwindSafe for Recursive
impl Send for Recursive
impl Sync for Recursive
impl Unpin for Recursive
impl UnwindSafe for Recursive
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