Struct rpds::map::red_black_tree_map::RedBlackTreeMap
source · 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() -> RedBlackTreeMapSync<K, V>
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
pub fn size(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn iter(&self) -> Iter<'_, K, V, P>
pub fn keys(&self) -> IterKeys<'_, K, V, P>
pub fn values(&self) -> IterValues<'_, K, V, P>
pub fn range<Q, RB>(&self, range: RB) -> RangeIter<'_, K, V, RB, Q, P>
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 copy 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: Debug, V: Debug, P> Debug for RedBlackTreeMap<K, V, P>where
P: SharedPointerKind + Debug,
impl<K: Debug, V: Debug, P> Debug for RedBlackTreeMap<K, V, P>where
P: SharedPointerKind + Debug,
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<'de>>(
deserializer: D
) -> Result<RedBlackTreeMap<K, V, P>, D::Error>
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>
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: IntoIterator<Item = (K, V)>>(
into_iter: I
) -> RedBlackTreeMap<K, V, P>
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>
impl<K, V: Hash, P: SharedPointerKind> Hash for RedBlackTreeMap<K, V, P>
source§impl<'a, K, Q, V, P> Index<&'a Q> for RedBlackTreeMap<K, V, P>
impl<'a, K, Q, V, P> Index<&'a 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: Ord, V: Ord, P> Ord for RedBlackTreeMap<K, V, P>where
P: SharedPointerKind,
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
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: PartialEq, P, PO> PartialEq<RedBlackTreeMap<K, V, PO>> for RedBlackTreeMap<K, V, P>
impl<K, V: PartialEq, P, PO> PartialEq<RedBlackTreeMap<K, V, PO>> for RedBlackTreeMap<K, V, P>
source§fn eq(&self, other: &RedBlackTreeMap<K, V, PO>) -> bool
fn eq(&self, other: &RedBlackTreeMap<K, V, PO>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl<K: Ord, V: PartialOrd, P, PO> PartialOrd<RedBlackTreeMap<K, V, PO>> for RedBlackTreeMap<K, V, P>where
P: SharedPointerKind,
PO: SharedPointerKind,
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>
fn partial_cmp(&self, other: &RedBlackTreeMap<K, V, PO>) -> Option<Ordering>
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 moresource§impl<K, V, P> Serialize for RedBlackTreeMap<K, V, P>
impl<K, V, P> Serialize for RedBlackTreeMap<K, V, P>
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>
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