Struct rpds::map::red_black_tree_map::RedBlackTreeMap
[−]
[src]
pub struct RedBlackTreeMap<K, V> { /* fields omitted */ }
A persistent map with structural sharing. This implementation uses a
red-black tree
and supports fast insert()
, remove()
, and get()
.
Complexity
Let n be the number of elements in the map.
Temporal complexity
Operation | Best case | Average | Worst case |
---|---|---|---|
new() |
Θ(1) | Θ(1) | Θ(1) |
insert() |
Θ(1) | Θ(log(n)) | Θ(log(n)) |
remove() |
Θ(1) | Θ(log(n)) | Θ(log(n)) |
get() |
Θ(1) | Θ(log(n)) | Θ(log(n)) |
contains_key() |
Θ(1) | Θ(log(n)) | Θ(log(n)) |
size() |
Θ(1) | Θ(1) | Θ(1) |
clone() |
Θ(1) | Θ(1) | Θ(1) |
iterator creation | Θ(1) | Θ(1) | Θ(1) |
iterator step | Θ(1) | Θ(1) | Θ(log(n)) |
iterator full | Θ(n) | Θ(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)
Methods
impl<K, V> RedBlackTreeMap<K, V> where
K: Ord,
[src]
K: Ord,
fn new() -> RedBlackTreeMap<K, V>
[src]
fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
K: Borrow<Q>,
Q: Ord,
[src]
K: Borrow<Q>,
Q: Ord,
fn first(&self) -> Option<(&K, &V)>
[src]
fn last(&self) -> Option<(&K, &V)>
[src]
fn insert(&self, key: K, value: V) -> RedBlackTreeMap<K, V>
[src]
fn remove<Q: ?Sized>(&self, key: &Q) -> RedBlackTreeMap<K, V> where
K: Borrow<Q>,
Q: Ord,
[src]
K: Borrow<Q>,
Q: Ord,
fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Ord,
[src]
K: Borrow<Q>,
Q: Ord,
fn size(&self) -> usize
[src]
fn is_empty(&self) -> bool
[src]
fn iter(&self) -> Iter<K, V>
[src]
fn keys(&self) -> IterKeys<K, V>
[src]
fn values(&self) -> IterValues<K, V>
[src]
Trait Implementations
impl<K, V> Serialize for RedBlackTreeMap<K, V> where
K: Ord + Serialize,
V: Serialize,
[src]
K: Ord + Serialize,
V: Serialize,
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
[src]
Serialize this value into the given Serde serializer. Read more
impl<'de, K, V> Deserialize<'de> for RedBlackTreeMap<K, V> where
K: Ord + Deserialize<'de>,
V: Deserialize<'de>,
[src]
K: Ord + Deserialize<'de>,
V: Deserialize<'de>,
fn deserialize<D: Deserializer<'de>>(
deserializer: D
) -> Result<RedBlackTreeMap<K, V>, D::Error>
[src]
deserializer: D
) -> Result<RedBlackTreeMap<K, V>, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl<K: Debug, V: Debug> Debug for RedBlackTreeMap<K, V>
[src]
impl<'a, K, Q: ?Sized, V> Index<&'a Q> for RedBlackTreeMap<K, V> where
K: Ord + Borrow<Q>,
Q: Ord,
[src]
K: Ord + Borrow<Q>,
Q: Ord,
type Output = V
The returned type after indexing.
fn index(&self, key: &Q) -> &V
[src]
Performs the indexing (container[index]
) operation.
impl<K, V> Clone for RedBlackTreeMap<K, V> where
K: Ord,
[src]
K: Ord,
fn clone(&self) -> RedBlackTreeMap<K, V>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<K, V> Default for RedBlackTreeMap<K, V> where
K: Ord,
[src]
K: Ord,
fn default() -> RedBlackTreeMap<K, V>
[src]
Returns the "default value" for a type. Read more
impl<K, V: PartialEq> PartialEq for RedBlackTreeMap<K, V> where
K: Ord,
[src]
K: Ord,
fn eq(&self, other: &RedBlackTreeMap<K, V>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<K, V: Eq> Eq for RedBlackTreeMap<K, V> where
K: Ord,
[src]
K: Ord,
impl<K: Ord, V: PartialOrd> PartialOrd for RedBlackTreeMap<K, V>
[src]
fn partial_cmp(&self, other: &RedBlackTreeMap<K, V>) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<K: Ord, V: Ord> Ord for RedBlackTreeMap<K, V>
[src]
fn cmp(&self, other: &RedBlackTreeMap<K, V>) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl<K: Hash, V: Hash> Hash for RedBlackTreeMap<K, V> where
K: Ord,
[src]
K: Ord,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<K, V> Display for RedBlackTreeMap<K, V> where
K: Ord + Display,
V: Display,
[src]
K: Ord + Display,
V: Display,
fn fmt(&self, fmt: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<'a, K, V> IntoIterator for &'a RedBlackTreeMap<K, V> where
K: Ord,
[src]
K: Ord,
type Item = (&'a K, &'a V)
The type of the elements being iterated over.
type IntoIter = Iter<'a, K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Iter<'a, K, V>
[src]
Creates an iterator from a value. Read more
impl<K, V> FromIterator<(K, V)> for RedBlackTreeMap<K, V> where
K: Ord,
[src]
K: Ord,
fn from_iter<I: IntoIterator<Item = (K, V)>>(
into_iter: I
) -> RedBlackTreeMap<K, V>
[src]
into_iter: I
) -> RedBlackTreeMap<K, V>
Creates a value from an iterator. Read more