Vector

Struct Vector 

Source
pub struct Vector<T> { /* private fields */ }
Expand description

Tiered vector which maintains a collection of circular deques in order to efficiently support insert and remove from any location within the vector.

Implementations§

Source§

impl<T> Vector<T>

Source

pub fn new() -> Self

Return an empty vector with zero capacity.

Source

pub fn insert(&mut self, index: usize, value: T)

Inserts an element at position index within the array, shifting some elements to the right as needed.

Source

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

Appends an element to the back of a collection.

§Panics

Panics if a new block is allocated that would exceed isize::MAX bytes.

§Time complexity

O(√N) in the worst case.

Source

pub fn push_within_capacity(&mut self, value: T) -> Result<(), T>

Appends an element if there is sufficient spare capacity, otherwise an error is returned with the element.

§Time complexity

O(√N) in the worst case.

Source

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

Retrieve a reference to the element at the given offset.

§Time complexity

Constant time.

Source

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

Returns a mutable reference to an element.

§Time complexity

Constant time.

Source

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

Removes an element from position index within the array, shifting some elements to the left as needed to close the gap.

§Time complexity

O(√N) in the worst case.

Source

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

Removes the last element from the vector and returns it, or None if the vector is empty.

§Time complexity

O(√N) in the worst case.

Source

pub fn pop_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T>

Removes and returns the last element from a vector if the predicate returns true, or None`` if the predicate returns false`` or the vector is empty (the predicate will not be called in that case).

§Time complexity

O(√N) in the worst case.

Source

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

Source

pub fn len(&self) -> usize

Return the number of elements in the vector.

§Time complexity

Constant time.

Source

pub fn capacity(&self) -> usize

Returns the total number of elements the vector can hold without reallocating.

§Time complexity

Constant time.

Source

pub fn is_empty(&self) -> bool

Returns true if the array has a length of 0.

§Time complexity

Constant time.

Source

pub fn clear(&mut self)

Clears the vector, removing all values and deallocating all blocks.

§Time complexity

O(n) if elements are droppable, otherwise O(√N)

Trait Implementations§

Source§

impl<T> Default for Vector<T>

Source§

fn default() -> Self

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

impl<T> Display for Vector<T>

Source§

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

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

impl<A> FromIterator<A> for Vector<A>

Source§

fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> Index<usize> for Vector<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

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

impl<T> IndexMut<usize> for Vector<T>

Source§

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

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

impl<T> IntoIterator for Vector<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = VectorIntoIter<<Vector<T> as IntoIterator>::Item>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Vector<T>

§

impl<T> RefUnwindSafe for Vector<T>
where T: RefUnwindSafe,

§

impl<T> !Send for Vector<T>

§

impl<T> !Sync for Vector<T>

§

impl<T> Unpin for Vector<T>

§

impl<T> UnwindSafe for Vector<T>
where T: RefUnwindSafe,

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.