use crate::{Fragment, Growth, SplitVec};
impl<T> SplitVec<T> {
pub fn new() -> Self {
Self::with_doubling_growth()
}
}
impl<T, G> SplitVec<T, G>
where
G: Growth,
{
pub fn with_growth(growth: G) -> Self {
let capacity = Growth::new_fragment_capacity::<T>(&growth, &[]);
let fragment = Fragment::new(capacity);
let fragments = alloc::vec![fragment];
SplitVec::from_raw_parts(0, fragments, growth)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{Doubling, Linear};
#[test]
fn new() {
let vec: SplitVec<usize> = SplitVec::new();
let vec: SplitVec<usize, Doubling> = vec;
assert_eq!(1, vec.fragments().len());
assert_eq!(4, vec.fragments()[0].capacity());
}
#[test]
fn with_initial_capacity() {
let vec: SplitVec<usize> = SplitVec::new();
let vec: SplitVec<usize, Doubling> = vec;
assert_eq!(1, vec.fragments().len());
assert_eq!(4, vec.fragments()[0].capacity());
}
#[test]
fn with_growth() {
let vec: SplitVec<char, Linear> = SplitVec::with_growth(Linear::new(3));
assert_eq!(1, vec.fragments().len());
assert_eq!(8, vec.fragments()[0].capacity());
let vec: SplitVec<char, Doubling> = SplitVec::with_growth(Doubling);
assert_eq!(1, vec.fragments().len());
assert_eq!(4, vec.fragments()[0].capacity());
}
}