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