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.
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 get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Gets the item at index
, or None
if no such item exists.
sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
Gets a mutable reference to the item at index
, or None
if no such
item exists.
sourcepub fn first(&self) -> Option<&T>
pub fn first(&self) -> Option<&T>
Gets the first item in the vector, or None
if the vector is empty.
sourcepub fn first_mut(&mut self) -> Option<&mut T>
pub fn first_mut(&mut self) -> Option<&mut T>
Gets a mutable reference to the first item in the vector, or None
if the vector is empty.
sourcepub fn last(&self) -> Option<&T>
pub fn last(&self) -> Option<&T>
Gets the last item in the vector, or None
if the vector is empty.
sourcepub fn last_mut(&mut self) -> Option<&mut T>
pub fn last_mut(&mut self) -> Option<&mut T>
Gets a mutable reference to the last item in the vector, or None
if
the vector is empty.
sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes and returns the last item in the vector, or None
if the
vector is empty.