Struct rpds::vector::Vector

source ·
pub struct Vector<T, P = RcK>{ /* private fields */ }
Expand description

A persistent vector with structural sharing.

Complexity

Let n be the number of elements in the vector.

Temporal complexity

OperationAverageWorst case
new()Θ(1)Θ(1)
set()Θ(log(n))Θ(log(n))
push_back()Θ(log(n))Θ(log(n))
drop_last()Θ(log(n))Θ(log(n))
first()/last()/get()Θ(log(n))Θ(log(n))
len()Θ(1)Θ(1)
clone()Θ(1)Θ(1)
iterator creationΘ(1)Θ(1)
iterator stepΘ(1)Θ(log(n))
iterator fullΘ(n)Θ(n)

Implementation details

This implementation uses a bitmapped vector trie as described in Understanding Persistent Vector Part 1 and Understanding Persistent Vector Part 2.

Implementations§

source§

impl<T> Vector<T, ArcTK>

source

pub fn new_sync() -> VectorSync<T>

source§

impl<T> Vector<T>

source

pub fn new() -> Vector<T>

source§

impl<T, P> Vector<T, P>

source

pub fn new_with_ptr_kind() -> Vector<T, P>

source

pub fn new_with_bits(bits: u8) -> Vector<T, P>

source

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

source

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

source

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

source

pub fn set(&self, index: usize, v: T) -> Option<Vector<T, P>>

source

pub fn set_mut(&mut self, index: usize, v: T) -> bool

Returns true if the operation was successful.

source

pub fn push_back(&self, v: T) -> Vector<T, P>

source

pub fn push_back_mut(&mut self, v: T)

source

pub fn drop_last(&self) -> Option<Vector<T, P>>

source

pub fn drop_last_mut(&mut self) -> bool

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

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

source§

impl<T: Clone, P> Vector<T, P>

source

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

Gets a mutable reference to an element. If the element is shared, it will be cloned. Returns None if and only if the given index is out of range.

Trait Implementations§

source§

impl<T, P> Clone for Vector<T, P>

source§

fn clone(&self) -> Vector<T, P>

Returns a copy 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, P> Debug for Vector<T, P>

source§

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

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

impl<T, P> Default for Vector<T, P>

source§

fn default() -> Vector<T, P>

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

impl<'de, T, P> Deserialize<'de> for Vector<T, P>
where T: Deserialize<'de>, P: SharedPointerKind,

source§

fn deserialize<D: Deserializer<'de>>( deserializer: D ) -> Result<Vector<T, P>, D::Error>

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: Display, P> Display for Vector<T, P>

source§

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

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

impl<T, P> Extend<T> for Vector<T, P>

source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T, P> FromIterator<T> for Vector<T, P>

source§

fn from_iter<I: IntoIterator<Item = T>>(into_iter: I) -> Vector<T, P>

Creates a value from an iterator. Read more
source§

impl<T: Hash, P> Hash for Vector<T, P>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

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

§

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: Clone, P> IndexMut<usize> for Vector<T, P>

source§

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

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

impl<'a, T, P> IntoIterator for &'a Vector<T, P>

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = Map<IterPtr<'a, T, P>, fn(_: &SharedPointer<T, P>) -> &T>

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

fn into_iter(self) -> Iter<'a, T, P>

Creates an iterator from a value. Read more
source§

impl<T: Ord, P> Ord for Vector<T, P>

source§

fn cmp(&self, other: &Vector<T, P>) -> 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 + PartialOrd,

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

impl<T: PartialEq<U>, U, P, PO> PartialEq<Vector<U, PO>> for Vector<T, P>

source§

fn eq(&self, other: &Vector<U, PO>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd<U>, U, P, PO> PartialOrd<Vector<U, PO>> for Vector<T, P>

source§

fn partial_cmp(&self, other: &Vector<U, PO>) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, P> Serialize for Vector<T, P>

source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Eq, P> Eq for Vector<T, P>

Auto Trait Implementations§

§

impl<T, P> RefUnwindSafe for Vector<T, P>

§

impl<T, P> Send for Vector<T, P>
where P: Send + Sync, T: Send + Sync,

§

impl<T, P> Sync for Vector<T, P>
where P: Send + Sync, T: Send + Sync,

§

impl<T, P> Unpin for Vector<T, P>

§

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

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> ToOwned for T
where T: Clone,

§

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

source§

default 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>,

§

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

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,