pub struct Vector<T, P = RcK>where
P: SharedPointerKind,{ /* private fields */ }
Expand description
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) |
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, P> Vector<T, P>where
P: SharedPointerKind,
impl<T, P> Vector<T, P>where
P: SharedPointerKind,
pub fn new_with_ptr_kind() -> Vector<T, P>
pub fn new_with_bits(bits: u8) -> Vector<T, P>
pub fn first(&self) -> Option<&T>
pub fn last(&self) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
pub fn set(&self, index: usize, v: T) -> Option<Vector<T, P>>
sourcepub fn set_mut(&mut self, index: usize, v: T) -> bool
pub fn set_mut(&mut self, index: usize, v: T) -> bool
Returns true
if the operation was successful.
pub fn push_back(&self, v: T) -> Vector<T, P>
pub fn push_back_mut(&mut self, v: T)
pub fn drop_last(&self) -> Option<Vector<T, P>>
pub fn drop_last_mut(&mut self) -> bool
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn iter(&self) -> Iter<'_, T, P>
Trait Implementations§
source§impl<T, P> Clone for Vector<T, P>where
P: SharedPointerKind,
impl<T, P> Clone for Vector<T, P>where
P: SharedPointerKind,
source§impl<T, P> Default for Vector<T, P>where
P: SharedPointerKind,
impl<T, P> Default for Vector<T, P>where
P: SharedPointerKind,
source§impl<'de, T, P> Deserialize<'de> for Vector<T, P>where
T: Deserialize<'de>,
P: SharedPointerKind,
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>
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, P> Extend<T> for Vector<T, P>where
P: SharedPointerKind,
impl<T, P> Extend<T> for Vector<T, P>where
P: SharedPointerKind,
source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
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)
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)
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>where
P: SharedPointerKind,
impl<T, P> FromIterator<T> for Vector<T, P>where
P: SharedPointerKind,
source§impl<'a, T, P> IntoIterator for &'a Vector<T, P>where
P: SharedPointerKind,
impl<'a, T, P> IntoIterator for &'a Vector<T, P>where
P: SharedPointerKind,
source§impl<T: Ord, P> Ord for Vector<T, P>where
P: SharedPointerKind,
impl<T: Ord, P> Ord for Vector<T, P>where
P: SharedPointerKind,
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<T: PartialEq<U>, U, P, PO> PartialEq<Vector<U, PO>> for Vector<T, P>where
P: SharedPointerKind,
PO: SharedPointerKind,
impl<T: PartialEq<U>, U, P, PO> PartialEq<Vector<U, PO>> for Vector<T, P>where
P: SharedPointerKind,
PO: SharedPointerKind,
source§impl<T: PartialOrd<U>, U, P, PO> PartialOrd<Vector<U, PO>> for Vector<T, P>where
P: SharedPointerKind,
PO: SharedPointerKind,
impl<T: PartialOrd<U>, U, P, PO> PartialOrd<Vector<U, PO>> for Vector<T, P>where
P: SharedPointerKind,
PO: SharedPointerKind,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moreimpl<T: Eq, P> Eq for Vector<T, P>where
P: SharedPointerKind,
Auto Trait Implementations§
impl<T, P> RefUnwindSafe for Vector<T, P>where
P: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, P> Send for Vector<T, P>
impl<T, P> Sync for Vector<T, P>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more