pub struct RedBlackTreeMap<K, V, P = RcK>where
    P: SharedPointerKind,{ /* private fields */ }
Expand description

A persistent map with structural sharing. This implementation uses a red-black tree.

Complexity

Let n be the number of elements in the map.

Temporal complexity

OperationAverageWorst case
new()Θ(1)Θ(1)
insert()Θ(log(n))Θ(log(n))
remove()Θ(log(n))Θ(log(n))
get()Θ(log(n))Θ(log(n))
contains_key()Θ(log(n))Θ(log(n))
size()Θ(1)Θ(1)
clone()Θ(1)Θ(1)
iterator creationΘ(log(n))Θ(log(n))
iterator stepΘ(1)Θ(log(n))
iterator fullΘ(n)Θ(n)

Implementation details

This implementation uses a red-black tree as described in “Purely Functional Data Structures” by Chris Okasaki, page 27. Deletion is implemented according to the paper “Red-Black Trees with Types” by Stefan Kahrs (reference implementation)

Implementations§

source§

impl<K, V> RedBlackTreeMap<K, V, ArcK>where K: Ord,

source§

impl<K, V> RedBlackTreeMap<K, V>where K: Ord,

source

pub fn new() -> RedBlackTreeMap<K, V>

source§

impl<K, V, P> RedBlackTreeMap<K, V, P>where K: Ord, P: SharedPointerKind,

source

pub fn new_with_ptr_kind() -> RedBlackTreeMap<K, V, P>

source

pub fn get<Q>(&self, key: &Q) -> Option<&V>where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn first(&self) -> Option<(&K, &V)>

source

pub fn last(&self) -> Option<(&K, &V)>

source

pub fn insert(&self, key: K, value: V) -> RedBlackTreeMap<K, V, P>

source

pub fn insert_mut(&mut self, key: K, value: V)

source

pub fn remove<Q>(&self, key: &Q) -> RedBlackTreeMap<K, V, P>where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn remove_mut<Q>(&mut self, key: &Q) -> boolwhere K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn contains_key<Q>(&self, key: &Q) -> boolwhere K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn size(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

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

source

pub fn keys(&self) -> IterKeys<'_, K, V, P>

source

pub fn values(&self) -> IterValues<'_, K, V, P>

source

pub fn range<Q, RB>(&self, range: RB) -> RangeIter<'_, K, V, RB, Q, P>where K: Borrow<Q>, Q: Ord + ?Sized, RB: RangeBounds<Q>,

source§

impl<K, V, P> RedBlackTreeMap<K, V, P>where K: Ord + Clone, V: Clone, P: SharedPointerKind,

source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>where K: Borrow<Q>, Q: Ord + ?Sized,

Trait Implementations§

source§

impl<K, V, P> Clone for RedBlackTreeMap<K, V, P>where K: Ord, P: SharedPointerKind,

source§

fn clone(&self) -> RedBlackTreeMap<K, V, 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<K: Debug, V: Debug, P> Debug for RedBlackTreeMap<K, V, P>where P: SharedPointerKind + Debug,

source§

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

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

impl<K, V, P> Default for RedBlackTreeMap<K, V, P>where K: Ord, P: SharedPointerKind,

source§

fn default() -> RedBlackTreeMap<K, V, P>

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

impl<'de, K, V, P> Deserialize<'de> for RedBlackTreeMap<K, V, P>where K: Ord + Deserialize<'de>, V: Deserialize<'de>, P: SharedPointerKind,

source§

fn deserialize<D: Deserializer<'de>>( deserializer: D ) -> Result<RedBlackTreeMap<K, V, P>, D::Error>

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

impl<K, V, P> Display for RedBlackTreeMap<K, V, P>where K: Ord + Display, V: Display, P: SharedPointerKind,

source§

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

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

impl<K, V, P> FromIterator<(K, V)> for RedBlackTreeMap<K, V, P>where K: Ord, P: SharedPointerKind,

source§

fn from_iter<I: IntoIterator<Item = (K, V)>>( into_iter: I ) -> RedBlackTreeMap<K, V, P>

Creates a value from an iterator. Read more
source§

impl<K, V: Hash, P: SharedPointerKind> Hash for RedBlackTreeMap<K, V, P>where K: Ord + Hash,

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<'a, K, Q, V, P> Index<&'a Q> for RedBlackTreeMap<K, V, P>where K: Ord + Borrow<Q>, Q: Ord + ?Sized, P: SharedPointerKind,

§

type Output = V

The returned type after indexing.
source§

fn index(&self, key: &Q) -> &V

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

impl<'a, K, V, P> IntoIterator for &'a RedBlackTreeMap<K, V, P>where K: Ord, P: SharedPointerKind,

§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
§

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

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

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

Creates an iterator from a value. Read more
source§

impl<K: Ord, V: Ord, P> Ord for RedBlackTreeMap<K, V, P>where P: SharedPointerKind,

source§

fn cmp(&self, other: &RedBlackTreeMap<K, V, P>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

impl<K, V: PartialEq, P, PO> PartialEq<RedBlackTreeMap<K, V, PO>> for RedBlackTreeMap<K, V, P>where K: Ord, P: SharedPointerKind, PO: SharedPointerKind,

source§

fn eq(&self, other: &RedBlackTreeMap<K, V, 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<K: Ord, V: PartialOrd, P, PO> PartialOrd<RedBlackTreeMap<K, V, PO>> for RedBlackTreeMap<K, V, P>where P: SharedPointerKind, PO: SharedPointerKind,

source§

fn partial_cmp(&self, other: &RedBlackTreeMap<K, V, 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<K, V, P> Serialize for RedBlackTreeMap<K, V, P>where K: Ord + Serialize, V: Serialize, P: SharedPointerKind,

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<K, V: Eq, P> Eq for RedBlackTreeMap<K, V, P>where K: Ord, P: SharedPointerKind,

Auto Trait Implementations§

§

impl<K, V, P> RefUnwindSafe for RedBlackTreeMap<K, V, P>where K: RefUnwindSafe, P: RefUnwindSafe, V: RefUnwindSafe,

§

impl<K, V, P> Send for RedBlackTreeMap<K, V, P>where K: Send + Sync, P: Send + Sync, V: Send + Sync,

§

impl<K, V, P> Sync for RedBlackTreeMap<K, V, P>where K: Send + Sync, P: Send + Sync, V: Send + Sync,

§

impl<K, V, P> Unpin for RedBlackTreeMap<K, V, P>

§

impl<K, V, P> UnwindSafe for RedBlackTreeMap<K, V, P>where K: UnwindSafe, P: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere T: for<'de> Deserialize<'de>,