Struct rpds::sequence::vector::Vector [] [src]

pub struct Vector<T> { /* fields omitted */ }

A persistent vector with structural sharing. This data structure supports fast push_back(), set(), drop_last(), and get().

Complexity

Let n be the number of elements in the vector.

Temporal complexity

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

Proof sketch of the complexity of full iteration

  1. A tree of size n and degree d has height ⌈logd(n)⌉ - 1.
  2. A complete iteration is a depth-first search on the tree.
  3. A depth-first search has complexity Θ(|V| + |E|), where |V| is the number of nodes and |E| the number of edges.
  4. The number of nodes |V| for a complete tree of height h is the sum of powers of d, which is (dʰ - 1) / (d - 1). See Calculating sum of consecutive powers of a number.
  5. The number of edges is exactly |V| - 1.

By 2. and 3. we have that the complexity of a full iteration is

     Θ(|V| + |E|)
   = Θ((dʰ - 1) / (d - 1))      (by 4. and 5.)
   = Θ(dʰ)
   = Θ(n)                       (by 1.)

Implementation details

This vector is implemented as described in Understanding Persistent Vector Part 1 and Understanding Persistent Vector Part 2.

Methods

impl<T> Vector<T>
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

Trait Implementations

impl<T> Serialize for Vector<T> where
    T: Serialize
[src]

[src]

Serialize this value into the given Serde serializer. Read more

impl<'de, T> Deserialize<'de> for Vector<T> where
    T: Deserialize<'de>, 
[src]

[src]

Deserialize this value from the given Serde deserializer. Read more

impl<T: Debug> Debug for Vector<T>
[src]

[src]

Formats the value using the given formatter. Read more

impl<T> Index<usize> for Vector<T>
[src]

The returned type after indexing.

[src]

Performs the indexing (container[index]) operation.

impl<T> Default for Vector<T>
[src]

[src]

Returns the "default value" for a type. Read more

impl<T: PartialEq> PartialEq for Vector<T>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<T: Eq> Eq for Vector<T>
[src]

impl<T: PartialOrd<T>> PartialOrd<Vector<T>> for Vector<T>
[src]

[src]

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

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

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

impl<T: Ord> Ord for Vector<T>
[src]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl<T: Hash> Hash for Vector<T>
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<T> Clone for Vector<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T> Display for Vector<T> where
    T: Display
[src]

[src]

Formats the value using the given formatter. Read more

impl<'a, T> IntoIterator for &'a Vector<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<T> FromIterator<T> for Vector<T>
[src]

[src]

Creates a value from an iterator. Read more

Auto Trait Implementations

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

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