[−][src]Struct rpds::vector::Vector
A persistent vector with structural sharing.
Complexity
Let n be the number of elements in the vector.
Temporal complexity
Operation | Average | Worst 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) |
Proof sketch of the complexity of full iteration
- A tree of size n and degree d has height ⌈logd(n)⌉ - 1.
- A complete iteration is a depth-first search on the tree.
- A depth-first search has complexity Θ(|V| + |E|), where |V| is the number of nodes and |E| the number of edges.
- 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.
- 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 implementation uses a bitmapped vector trie as described in Understanding Persistent Vector Part 1 and Understanding Persistent Vector Part 2.
Methods
impl<T> Vector<T>
[src]
#[must_use]
pub fn new() -> Vector<T>
[src]
#[must_use]
pub fn new_with_bits(bits: u8) -> Vector<T>
[src]
#[must_use]
pub fn first(&self) -> Option<&T>
[src]
#[must_use]
pub fn last(&self) -> Option<&T>
[src]
#[must_use]
pub fn get(&self, index: usize) -> Option<&T>
[src]
#[must_use]
pub fn set(&self, index: usize, v: T) -> Option<Vector<T>>
[src]
pub fn set_mut(&mut self, index: usize, v: T) -> bool
[src]
Returns true
if the operation was successful.
#[must_use]
pub fn push_back(&self, v: T) -> Vector<T>
[src]
pub fn push_back_mut(&mut self, v: T)
[src]
#[must_use]
pub fn drop_last(&self) -> Option<Vector<T>>
[src]
pub fn drop_last_mut(&mut self) -> bool
[src]
#[must_use]
pub fn len(&self) -> usize
[src]
#[must_use]
pub fn is_empty(&self) -> bool
[src]
#[must_use]
pub fn iter(&self) -> Iter<T>
[src]
impl<T: Clone> Vector<T>
[src]
#[must_use]
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
[src]
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
impl<T> Extend<T> for Vector<T>
[src]
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
[src]
impl<T> Default for Vector<T>
[src]
impl<T: PartialEq<U>, U> PartialEq<Vector<U>> for Vector<T>
[src]
fn eq(&self, other: &Vector<U>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<T: PartialOrd<U>, U> PartialOrd<Vector<U>> for Vector<T>
[src]
fn partial_cmp(&self, other: &Vector<U>) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
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: Eq> Eq for Vector<T>
[src]
impl<T: Ord> Ord for Vector<T>
[src]
fn cmp(&self, other: &Vector<T>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl<T> Clone for Vector<T>
[src]
fn clone(&self) -> Vector<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'a, T> IntoIterator for &'a Vector<T>
[src]
type Item = &'a T
The type of the elements being iterated over.
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Iter<'a, T>
[src]
impl<T: Clone> IndexMut<usize> for Vector<T>
[src]
impl<T: Debug> Debug for Vector<T>
[src]
impl<T> Display for Vector<T> where
T: Display,
[src]
T: Display,
impl<T: Hash> Hash for Vector<T>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T> Index<usize> for Vector<T>
[src]
impl<T> FromIterator<T> for Vector<T>
[src]
fn from_iter<I: IntoIterator<Item = T>>(into_iter: I) -> Vector<T>
[src]
impl<T> Serialize for Vector<T> where
T: Serialize,
[src]
T: Serialize,
impl<'de, T> Deserialize<'de> for Vector<T> where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
fn deserialize<D: Deserializer<'de>>(
deserializer: D
) -> Result<Vector<T>, D::Error>
[src]
deserializer: D
) -> Result<Vector<T>, D::Error>
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,