pub struct BTreeVec<T, const B: usize = 12, A: Allocator = Global> { /* private fields */ }Expand description
A growable array (vector) implemented as a B+ tree.
Provides non-amortized O(log n) random accesses, insertions, and removals, and O(n) iteration.
B is the branching factor. It must be at least 3. The standard library
uses a value of 6 for its B-tree structures. Larger values are better when
T is smaller.
§Mathematical variables
For the purposes of specifying the time complexity of various operations, n refers to the number of items in the vector.
Implementations§
Source§impl<T> BTreeVec<T>
impl<T> BTreeVec<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new BTreeVec. Note that this function is implemented
only for the default value of B; see Self::create for an
equivalent that works with all values of B.
Source§impl<T, A: Allocator> BTreeVec<T, 12, A>
impl<T, A: Allocator> BTreeVec<T, 12, A>
Sourcepub fn new_in(alloc: A) -> Self
pub fn new_in(alloc: A) -> Self
Creates a new BTreeVec with the given allocator. Note that this
function is implemented only for the default value of B; see
Self::create_in for an equivalent that works with all values of
B.
Source§impl<T, const B: usize> BTreeVec<T, B>
impl<T, const B: usize> BTreeVec<T, B>
Sourcepub fn create() -> Self
pub fn create() -> Self
Creates a new BTreeVec. This function exists because
BTreeVec::new is implemented only for the default value of B.
Source§impl<T, const B: usize, A: Allocator> BTreeVec<T, B, A>
impl<T, const B: usize, A: Allocator> BTreeVec<T, B, A>
Sourcepub fn create_in(alloc: A) -> Self
pub fn create_in(alloc: A) -> Self
Creates a new BTreeVec with the given allocator. This function
exists because BTreeVec::new_in is implemented only for the default
value of B.
Sourcepub fn insert(&mut self, index: usize, item: T)
pub fn insert(&mut self, index: usize, item: T)
Inserts item at index.
§Panics
Panics if index is greater than self.len().
§Time complexity
Θ(log n).
Sourcepub fn remove(&mut self, index: usize) -> T
pub fn remove(&mut self, index: usize) -> T
Removes and returns the item at index.
§Panics
Panics if index is not less than self.len().
§Time complexity
Θ(log n).