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
| Operation | Average | Worst 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,
impl<K, V> RedBlackTreeMap<K, V, ArcTK>where
K: Ord,
pub fn new_sync() -> RedBlackTreeMap<K, V, ArcTK>
Source§impl<K, V> RedBlackTreeMap<K, V>where
K: Ord,
impl<K, V> RedBlackTreeMap<K, V>where
K: Ord,
pub fn new() -> RedBlackTreeMap<K, V>
Source§impl<K, V, P> RedBlackTreeMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
impl<K, V, P> RedBlackTreeMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
pub fn new_with_ptr_kind() -> RedBlackTreeMap<K, V, P>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
pub fn first(&self) -> Option<(&K, &V)>
pub fn last(&self) -> Option<(&K, &V)>
pub fn insert(&self, key: K, value: V) -> RedBlackTreeMap<K, V, P>
pub fn insert_mut(&mut self, key: K, value: V)
pub fn remove<Q>(&self, key: &Q) -> RedBlackTreeMap<K, V, P>
pub fn remove_mut<Q>(&mut self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Sourcepub fn ptr_eq<PO>(&self, other: &RedBlackTreeMap<K, V, PO>) -> boolwhere
PO: SharedPointerKind,
pub fn ptr_eq<PO>(&self, other: &RedBlackTreeMap<K, V, PO>) -> boolwhere
PO: SharedPointerKind,
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.
pub fn size(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn iter( &self, ) -> Map<IterPtr<'_, K, V, P>, fn(&SharedPointer<Entry<K, V>, P>) -> (&K, &V)> ⓘ
pub fn keys( &self, ) -> Map<Map<IterPtr<'_, K, V, P>, fn(&SharedPointer<Entry<K, V>, P>) -> (&K, &V)>, fn((&K, &V)) -> &K> ⓘ
pub fn values( &self, ) -> Map<Map<IterPtr<'_, K, V, P>, fn(&SharedPointer<Entry<K, V>, P>) -> (&K, &V)>, fn((&K, &V)) -> &V> ⓘ
pub fn range<Q, RB>( &self, range: RB, ) -> Map<RangeIterPtr<'_, K, V, RB, Q, P>, fn(&SharedPointer<Entry<K, V>, P>) -> (&K, &V)> ⓘ
Trait Implementations§
Source§impl<K, V, P> Clone for RedBlackTreeMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
impl<K, V, P> Clone for RedBlackTreeMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
Source§fn clone(&self) -> RedBlackTreeMap<K, V, P>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<K, V, P> Debug for RedBlackTreeMap<K, V, P>
impl<K, V, P> Debug for RedBlackTreeMap<K, V, P>
Source§impl<K, V, P> Default for RedBlackTreeMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
impl<K, V, P> Default for RedBlackTreeMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
Source§fn default() -> RedBlackTreeMap<K, V, P>
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>
impl<'de, K, V, P> Deserialize<'de> for RedBlackTreeMap<K, V, P>
Source§fn deserialize<D>(
deserializer: D,
) -> Result<RedBlackTreeMap<K, V, P>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
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>
impl<K, V, P> Display for RedBlackTreeMap<K, V, P>
Source§impl<K, V, P> FromIterator<(K, V)> for RedBlackTreeMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
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)>,
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>
impl<K, V, P> Hash for RedBlackTreeMap<K, V, P>
Source§impl<K, Q, V, P> Index<&Q> for RedBlackTreeMap<K, V, P>
impl<K, Q, V, P> Index<&Q> for RedBlackTreeMap<K, V, P>
Source§impl<'a, K, V, P> IntoIterator for &'a RedBlackTreeMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
impl<'a, K, V, P> IntoIterator for &'a RedBlackTreeMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
Source§impl<K, V, P> Ord for RedBlackTreeMap<K, V, P>
impl<K, V, P> Ord for RedBlackTreeMap<K, V, P>
Source§fn cmp(&self, other: &RedBlackTreeMap<K, V, P>) -> Ordering
fn cmp(&self, other: &RedBlackTreeMap<K, V, P>) -> Ordering
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<K, V, P, PO> PartialEq<RedBlackTreeMap<K, V, PO>> for RedBlackTreeMap<K, V, P>
impl<K, V, P, PO> PartialEq<RedBlackTreeMap<K, V, PO>> for RedBlackTreeMap<K, V, P>
Source§impl<K, V, P, PO> PartialOrd<RedBlackTreeMap<K, V, PO>> for RedBlackTreeMap<K, V, P>
impl<K, V, P, PO> PartialOrd<RedBlackTreeMap<K, V, PO>> for RedBlackTreeMap<K, V, P>
Source§impl<K, V, P> Serialize for RedBlackTreeMap<K, V, P>
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,
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
impl<K, V, P> Eq for RedBlackTreeMap<K, V, P>
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>
impl<K, V, P> Sync for RedBlackTreeMap<K, V, P>
impl<K, V, P> Unpin for RedBlackTreeMap<K, V, P>
impl<K, V, P> UnwindSafe for RedBlackTreeMap<K, V, P>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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