RedBlackTreeMap

Struct RedBlackTreeMap 

Source
pub struct RedBlackTreeMap<K, V, P = RcK>{ /* 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, ArcTK>
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) -> bool
where K: Borrow<Q>, Q: Ord + ?Sized,

Source

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

Source

pub fn ptr_eq<PO>(&self, other: &RedBlackTreeMap<K, V, PO>) -> bool

Test whether the two maps refer to the same content in memory.

This would return true if you’re comparing a map to itself, or if you’re comparing a map to a fresh clone of itself.

Source

pub fn size(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn iter( &self, ) -> Map<IterPtr<'_, K, V, P>, fn(&SharedPointer<Entry<K, V>, P>) -> (&K, &V)>

Source

pub fn keys( &self, ) -> Map<Map<IterPtr<'_, K, V, P>, fn(&SharedPointer<Entry<K, V>, P>) -> (&K, &V)>, fn((&K, &V)) -> &K>

Source

pub fn values( &self, ) -> Map<Map<IterPtr<'_, K, V, P>, fn(&SharedPointer<Entry<K, V>, P>) -> (&K, &V)>, fn((&K, &V)) -> &V>

Source

pub fn range<Q, RB>( &self, range: RB, ) -> Map<RangeIterPtr<'_, K, V, RB, Q, P>, fn(&SharedPointer<Entry<K, V>, P>) -> (&K, &V)>
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 duplicate 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, V, P> Debug for RedBlackTreeMap<K, V, P>
where K: Debug, V: Debug, P: Debug + SharedPointerKind,

Source§

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

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: D, ) -> Result<RedBlackTreeMap<K, V, P>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

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<(), Error>

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>(into_iter: I) -> RedBlackTreeMap<K, V, P>
where I: IntoIterator<Item = (K, V)>,

Creates a value from an iterator. Read more
Source§

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

Source§

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

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

Source§

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,

Source§

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

The type of the elements being iterated over.
Source§

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, ) -> Map<IterPtr<'a, K, V, P>, fn(&'a SharedPointer<Entry<K, V>, P>) -> (&'a K, &'a V)>

Creates an iterator from a value. Read more
Source§

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

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

impl<K, V, P, PO> PartialEq<RedBlackTreeMap<K, V, PO>> for RedBlackTreeMap<K, V, P>

Source§

fn eq(&self, other: &RedBlackTreeMap<K, V, PO>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, V, P, PO> PartialOrd<RedBlackTreeMap<K, V, PO>> for RedBlackTreeMap<K, V, P>

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

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

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

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

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>

Source§

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

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

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<K, V, P> UnwindSafe for RedBlackTreeMap<K, V, P>
where P: UnwindSafe, K: UnwindSafe, V: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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§

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

Source§

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

Source§

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