BTreeVec

Struct BTreeVec 

Source
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>

Source

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>

Source

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>

Source

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>

Source

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.

Source

pub fn len(&self) -> usize

Gets the length of the vector.

§Time complexity

Constant.

Source

pub fn is_empty(&self) -> bool

Checks whether the vector is empty.

§Time complexity

Constant.

Source

pub fn get(&self, index: usize) -> Option<&T>

Gets the item at index, or None if no such item exists.

§Time complexity

Θ(log n).

Source

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.

§Time complexity

Θ(log n).

Source

pub fn first(&self) -> Option<&T>

Gets the first item in the vector, or None if the vector is empty.

§Time complexity

Θ(log n).

Source

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.

§Time complexity

Θ(log n).

Source

pub fn last(&self) -> Option<&T>

Gets the last item in the vector, or None if the vector is empty.

§Time complexity

Θ(log n).

Source

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.

§Time complexity

Θ(log n).

Source

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).

Source

pub fn push(&mut self, item: T)

Inserts item at the end of the vector.

§Time complexity

Θ(log n).

Source

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).

Source

pub fn pop(&mut self) -> Option<T>

Removes and returns the last item in the vector, or None if the vector is empty.

§Time complexity

Θ(log n).

Source

pub fn iter(&self) -> Iter<'_, T, B>

Gets an iterator that returns references to each item in the vector.

§Time complexity

Iteration over the entire vector is Θ(n).

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T, B>

Gets an iterator that returns mutable references to each item in the vector.

§Time complexity

Iteration over the entire vector is Θ(n).

Trait Implementations§

Source§

impl<T, const B: usize, A> Clone for BTreeVec<T, B, A>
where T: Clone, A: Clone + Allocator,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, const B: usize, A: Allocator> Debug for BTreeVec<T, B, A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const B: usize, A> Default for BTreeVec<T, B, A>
where A: Allocator + Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, const B: usize, A> Drop for BTreeVec<T, B, A>
where A: Allocator,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, const B: usize, A: Allocator> Index<usize> for BTreeVec<T, B, A>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const B: usize, A: Allocator> IndexMut<usize> for BTreeVec<T, B, A>

Source§

fn index_mut(&mut self, index: usize) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T, const B: usize, A> IntoIterator for &'a BTreeVec<T, B, A>
where A: Allocator,

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T, B>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T, const B: usize, A> IntoIterator for &'a mut BTreeVec<T, B, A>
where A: Allocator,

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T, B>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, const B: usize, A: Allocator> IntoIterator for BTreeVec<T, B, A>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, B, A>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, const B: usize, A> Ord for BTreeVec<T, B, A>
where T: Ord, A: Allocator,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T, const B: usize, A1, A2> PartialEq<BTreeVec<T, B, A2>> for BTreeVec<T, B, A1>
where T: PartialEq, A1: Allocator, A2: Allocator,

Source§

fn eq(&self, other: &BTreeVec<T, B, A2>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, const B: usize, A1, A2> PartialOrd<BTreeVec<T, B, A2>> for BTreeVec<T, B, A1>
where T: PartialOrd, A1: Allocator, A2: Allocator,

Source§

fn partial_cmp(&self, other: &BTreeVec<T, B, A2>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Eq, const B: usize, A: Allocator> Eq for BTreeVec<T, B, A>

Source§

impl<T, const B: usize, A> Send for BTreeVec<T, B, A>
where T: Send, A: Allocator,

Source§

impl<T, const B: usize, A> Sync for BTreeVec<T, B, A>
where T: Sync, A: Allocator,

Auto Trait Implementations§

§

impl<T, const B: usize, A> Freeze for BTreeVec<T, B, A>
where A: Freeze,

§

impl<T, const B: usize, A> RefUnwindSafe for BTreeVec<T, B, A>

§

impl<T, const B: usize, A> Unpin for BTreeVec<T, B, A>
where A: Unpin,

§

impl<T, const B: usize, A> UnwindSafe for BTreeVec<T, B, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.