pub struct GenericOrdMap<K, V, P>where
P: SharedPointerKind,{ /* private fields */ }
Expand description
An ordered map.
An immutable ordered map implemented as a B+tree 1.
Most operations on this type of map are O(log n). A
HashMap
is usually a better choice for
performance, but the OrdMap
has the advantage of only requiring
an Ord
constraint on the key, and of being
ordered, so that keys always come out from lowest to highest,
where a HashMap
has no guaranteed ordering.
Implementations§
Source§impl<K, V, P> GenericOrdMap<K, V, P>where
P: SharedPointerKind,
impl<K, V, P> GenericOrdMap<K, V, P>where
P: SharedPointerKind,
Sourcepub fn new() -> GenericOrdMap<K, V, P>
pub fn new() -> GenericOrdMap<K, V, P>
Construct an empty map.
Sourcepub fn unit(key: K, value: V) -> GenericOrdMap<K, V, P>
pub fn unit(key: K, value: V) -> GenericOrdMap<K, V, P>
Construct a map with a single mapping.
§Examples
let map = OrdMap::unit(123, "onetwothree");
assert_eq!(
map.get(&123),
Some(&"onetwothree")
);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Test whether a map is empty.
Time: O(1)
§Examples
assert!(
!ordmap!{1 => 2}.is_empty()
);
assert!(
OrdMap::<i32, i32>::new().is_empty()
);
Sourcepub fn ptr_eq(&self, other: &GenericOrdMap<K, V, P>) -> bool
pub fn ptr_eq(&self, other: &GenericOrdMap<K, V, P>) -> bool
Test whether two maps refer to the same content in memory.
This is true if the two sides are references to the same map, or if the two maps refer to the same root node.
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.
Time: O(1)
Source§impl<K, V, P> GenericOrdMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
impl<K, V, P> GenericOrdMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
Sourcepub fn get_max(&self) -> Option<&(K, V)>
pub fn get_max(&self) -> Option<&(K, V)>
Get the largest key in a map, along with its value. If the map
is empty, return None
.
Time: O(log n)
§Examples
assert_eq!(Some(&(3, 33)), ordmap!{
1 => 11,
2 => 22,
3 => 33
}.get_max());
Sourcepub fn get_min(&self) -> Option<&(K, V)>
pub fn get_min(&self) -> Option<&(K, V)>
Get the smallest key in a map, along with its value. If the
map is empty, return None
.
Time: O(log n)
§Examples
assert_eq!(Some(&(1, 11)), ordmap!{
1 => 11,
2 => 22,
3 => 33
}.get_min());
Sourcepub fn range<R, BK>(&self, range: R) -> RangedIter<'_, K, V, P> ⓘ
pub fn range<R, BK>(&self, range: R) -> RangedIter<'_, K, V, P> ⓘ
Create an iterator over a range of key/value pairs.
Sourcepub fn diff<'a, 'b>(
&'a self,
other: &'b GenericOrdMap<K, V, P>,
) -> DiffIter<'a, 'b, K, V, P> ⓘ
pub fn diff<'a, 'b>( &'a self, other: &'b GenericOrdMap<K, V, P>, ) -> DiffIter<'a, 'b, K, V, P> ⓘ
Get an iterator over the differences between this map and another, i.e. the set of entries to add, update, or remove to this map in order to make it equal to the other map.
This function will avoid visiting nodes which are shared between the two sets, meaning that even very large sets can be compared quickly if most of their structure is shared.
Time: O(n) where n is the size of the larger map.
Sourcepub fn get<BK>(&self, key: &BK) -> Option<&V>
pub fn get<BK>(&self, key: &BK) -> Option<&V>
Get the value for a key from a map.
Time: O(log n)
§Examples
let map = ordmap!{123 => "lol"};
assert_eq!(
map.get(&123),
Some(&"lol")
);
Sourcepub fn get_key_value<BK>(&self, key: &BK) -> Option<(&K, &V)>
pub fn get_key_value<BK>(&self, key: &BK) -> Option<(&K, &V)>
Get the key/value pair for a key from a map.
Time: O(log n)
§Examples
let map = ordmap!{123 => "lol"};
assert_eq!(
map.get_key_value(&123),
Some((&123, &"lol"))
);
Sourcepub fn get_prev<BK>(&self, key: &BK) -> Option<(&K, &V)>
pub fn get_prev<BK>(&self, key: &BK) -> Option<(&K, &V)>
Get a reference to the closest smaller entry in a map to a given key.
If the map contains the given key, this is returned.
Otherwise, the closest key in the map smaller than the
given value is returned. If the smallest key in the map
is larger than the given key, None
is returned.
§Examples
let map = ordmap![1 => 1, 3 => 3, 5 => 5];
assert_eq!(Some((&3, &3)), map.get_prev(&4));
Sourcepub fn get_next<BK>(&self, key: &BK) -> Option<(&K, &V)>
pub fn get_next<BK>(&self, key: &BK) -> Option<(&K, &V)>
Get a reference to the closest larger entry in a map to a given key.
If the set contains the given value, this is returned.
Otherwise, the closest value in the set larger than the
given value is returned. If the largest value in the set
is smaller than the given value, None
is returned.
§Examples
let map = ordmap![1 => 1, 3 => 3, 5 => 5];
assert_eq!(Some((&5, &5)), map.get_next(&4));
Sourcepub fn contains_key<BK>(&self, k: &BK) -> bool
pub fn contains_key<BK>(&self, k: &BK) -> bool
Test for the presence of a key in a map.
Time: O(log n)
§Examples
let map = ordmap!{123 => "lol"};
assert!(
map.contains_key(&123)
);
assert!(
!map.contains_key(&321)
);
Sourcepub fn is_submap_by<B, RM, F, P2>(&self, other: RM, cmp: F) -> bool
pub fn is_submap_by<B, RM, F, P2>(&self, other: RM, cmp: F) -> bool
Test whether a map is a submap of another map, meaning that all keys in our map must also be in the other map, with the same values.
Use the provided function to decide whether values are equal.
Time: O(n log n)
Sourcepub fn is_proper_submap_by<B, RM, F, P2>(&self, other: RM, cmp: F) -> bool
pub fn is_proper_submap_by<B, RM, F, P2>(&self, other: RM, cmp: F) -> bool
Test whether a map is a proper submap of another map, meaning that all keys in our map must also be in the other map, with the same values. To be a proper submap, ours must also contain fewer keys than the other map.
Use the provided function to decide whether values are equal.
Time: O(n log n)
Sourcepub fn is_submap<RM>(&self, other: RM) -> bool
pub fn is_submap<RM>(&self, other: RM) -> bool
Test whether a map is a submap of another map, meaning that all keys in our map must also be in the other map, with the same values.
Time: O(n log n)
§Examples
let map1 = ordmap!{1 => 1, 2 => 2};
let map2 = ordmap!{1 => 1, 2 => 2, 3 => 3};
assert!(map1.is_submap(map2));
Sourcepub fn is_proper_submap<RM>(&self, other: RM) -> bool
pub fn is_proper_submap<RM>(&self, other: RM) -> bool
Test whether a map is a proper submap of another map, meaning that all keys in our map must also be in the other map, with the same values. To be a proper submap, ours must also contain fewer keys than the other map.
Time: O(n log n)
§Examples
let map1 = ordmap!{1 => 1, 2 => 2};
let map2 = ordmap!{1 => 1, 2 => 2, 3 => 3};
assert!(map1.is_proper_submap(map2));
let map3 = ordmap!{1 => 1, 2 => 2};
let map4 = ordmap!{1 => 1, 2 => 2};
assert!(!map3.is_proper_submap(map4));
Source§impl<K, V, P> GenericOrdMap<K, V, P>
impl<K, V, P> GenericOrdMap<K, V, P>
Sourcepub fn get_mut<BK>(&mut self, key: &BK) -> Option<&mut V>
pub fn get_mut<BK>(&mut self, key: &BK) -> Option<&mut V>
Get a mutable reference to the value for a key from a map.
Time: O(log n)
§Examples
let mut map = ordmap!{123 => "lol"};
if let Some(value) = map.get_mut(&123) {
*value = "omg";
}
assert_eq!(
map.get(&123),
Some(&"omg")
);
Sourcepub fn get_key_value_mut<BK>(&mut self, key: &BK) -> Option<(&K, &mut V)>
pub fn get_key_value_mut<BK>(&mut self, key: &BK) -> Option<(&K, &mut V)>
Get the key/value pair for a key from a map.
Time: O(log n)
§Examples
let mut map = ordmap!{123 => "lol"};
assert_eq!(
map.get_key_value_mut(&123),
Some((&123, &mut "lol"))
);
Sourcepub fn get_prev_mut<BK>(&mut self, key: &BK) -> Option<(&K, &mut V)>
pub fn get_prev_mut<BK>(&mut self, key: &BK) -> Option<(&K, &mut V)>
Get the closest smaller entry in a map to a given key as a mutable reference.
If the map contains the given key, this is returned.
Otherwise, the closest key in the map smaller than the
given value is returned. If the smallest key in the map
is larger than the given key, None
is returned.
§Examples
let mut map = ordmap![1 => 1, 3 => 3, 5 => 5];
if let Some((key, value)) = map.get_prev_mut(&4) {
*value = 4;
}
assert_eq!(ordmap![1 => 1, 3 => 4, 5 => 5], map);
Sourcepub fn get_next_mut<BK>(&mut self, key: &BK) -> Option<(&K, &mut V)>
pub fn get_next_mut<BK>(&mut self, key: &BK) -> Option<(&K, &mut V)>
Get the closest larger entry in a map to a given key as a mutable reference.
If the set contains the given value, this is returned.
Otherwise, the closest value in the set larger than the
given value is returned. If the largest value in the set
is smaller than the given value, None
is returned.
§Examples
let mut map = ordmap![1 => 1, 3 => 3, 5 => 5];
if let Some((key, value)) = map.get_next_mut(&4) {
*value = 4;
}
assert_eq!(ordmap![1 => 1, 3 => 3, 5 => 4], map);
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Insert a key/value mapping into a map.
This is a copy-on-write operation, so that the parts of the map’s structure which are shared with other maps will be safely copied before mutating.
If the map already has a mapping for the given key, the previous value is overwritten.
Time: O(log n)
§Examples
let mut map = ordmap!{};
map.insert(123, "123");
map.insert(456, "456");
assert_eq!(
map,
ordmap!{123 => "123", 456 => "456"}
);
Sourcepub fn remove<BK>(&mut self, k: &BK) -> Option<V>
pub fn remove<BK>(&mut self, k: &BK) -> Option<V>
Remove a key/value mapping from a map if it exists.
Time: O(log n)
§Examples
let mut map = ordmap!{123 => "123", 456 => "456"};
map.remove(&123);
map.remove(&456);
assert!(map.is_empty());
Sourcepub fn remove_with_key<BK>(&mut self, k: &BK) -> Option<(K, V)>
pub fn remove_with_key<BK>(&mut self, k: &BK) -> Option<(K, V)>
Remove a key/value pair from a map, if it exists, and return the removed key and value.
Time: O(log n)
Sourcepub fn update(&self, key: K, value: V) -> GenericOrdMap<K, V, P>
pub fn update(&self, key: K, value: V) -> GenericOrdMap<K, V, P>
Construct a new map by inserting a key/value mapping into a map.
If the map already has a mapping for the given key, the previous value is overwritten.
Time: O(log n)
§Examples
let map = ordmap!{};
assert_eq!(
map.update(123, "123"),
ordmap!{123 => "123"}
);
Sourcepub fn update_with<F>(self, k: K, v: V, f: F) -> GenericOrdMap<K, V, P>where
F: FnOnce(V, V) -> V,
pub fn update_with<F>(self, k: K, v: V, f: F) -> GenericOrdMap<K, V, P>where
F: FnOnce(V, V) -> V,
Construct a new map by inserting a key/value mapping into a map.
If the map already has a mapping for the given key, we call the provided function with the old value and the new value, and insert the result as the new value.
Time: O(log n)
Sourcepub fn update_with_key<F>(self, k: K, v: V, f: F) -> GenericOrdMap<K, V, P>
pub fn update_with_key<F>(self, k: K, v: V, f: F) -> GenericOrdMap<K, V, P>
Construct a new map by inserting a key/value mapping into a map.
If the map already has a mapping for the given key, we call the provided function with the key, the old value and the new value, and insert the result as the new value.
Time: O(log n)
Sourcepub fn update_lookup_with_key<F>(
self,
k: K,
v: V,
f: F,
) -> (Option<V>, GenericOrdMap<K, V, P>)
pub fn update_lookup_with_key<F>( self, k: K, v: V, f: F, ) -> (Option<V>, GenericOrdMap<K, V, P>)
Construct a new map by inserting a key/value mapping into a map, returning the old value for the key as well as the new map.
If the map already has a mapping for the given key, we call the provided function with the key, the old value and the new value, and insert the result as the new value.
Time: O(log n)
Sourcepub fn alter<F>(&self, f: F, k: K) -> GenericOrdMap<K, V, P>
pub fn alter<F>(&self, f: F, k: K) -> GenericOrdMap<K, V, P>
Update the value for a given key by calling a function with the current value and overwriting it with the function’s return value.
The function gets an Option<V>
and
returns the same, so that it can decide to delete a mapping
instead of updating the value, and decide what to do if the
key isn’t in the map.
Time: O(log n)
Sourcepub fn without<BK>(&self, k: &BK) -> GenericOrdMap<K, V, P>
pub fn without<BK>(&self, k: &BK) -> GenericOrdMap<K, V, P>
Remove a key/value pair from a map, if it exists.
Time: O(log n)
Sourcepub fn extract<BK>(&self, k: &BK) -> Option<(V, GenericOrdMap<K, V, P>)>
pub fn extract<BK>(&self, k: &BK) -> Option<(V, GenericOrdMap<K, V, P>)>
Remove a key/value pair from a map, if it exists, and return the removed value as well as the updated list.
Time: O(log n)
Sourcepub fn extract_with_key<BK>(
&self,
k: &BK,
) -> Option<(K, V, GenericOrdMap<K, V, P>)>
pub fn extract_with_key<BK>( &self, k: &BK, ) -> Option<(K, V, GenericOrdMap<K, V, P>)>
Remove a key/value pair from a map, if it exists, and return the removed key and value as well as the updated list.
Time: O(log n)
Sourcepub fn union(self, other: GenericOrdMap<K, V, P>) -> GenericOrdMap<K, V, P>
pub fn union(self, other: GenericOrdMap<K, V, P>) -> GenericOrdMap<K, V, P>
Construct the union of two maps, keeping the values in the current map when keys exist in both maps.
Time: O(n log n)
§Examples
let map1 = ordmap!{1 => 1, 3 => 3};
let map2 = ordmap!{2 => 2, 3 => 4};
let expected = ordmap!{1 => 1, 2 => 2, 3 => 3};
assert_eq!(expected, map1.union(map2));
Sourcepub fn union_with<F>(
self,
other: GenericOrdMap<K, V, P>,
f: F,
) -> GenericOrdMap<K, V, P>where
F: FnMut(V, V) -> V,
pub fn union_with<F>(
self,
other: GenericOrdMap<K, V, P>,
f: F,
) -> GenericOrdMap<K, V, P>where
F: FnMut(V, V) -> V,
Construct the union of two maps, using a function to decide what to do with the value when a key is in both maps.
The function is called when a value exists in both maps, and receives the value from the current map as its first argument, and the value from the other map as the second. It should return the value to be inserted in the resulting map.
Time: O(n log n)
Sourcepub fn union_with_key<F>(
self,
other: GenericOrdMap<K, V, P>,
f: F,
) -> GenericOrdMap<K, V, P>
pub fn union_with_key<F>( self, other: GenericOrdMap<K, V, P>, f: F, ) -> GenericOrdMap<K, V, P>
Construct the union of two maps, using a function to decide what to do with the value when a key is in both maps.
The function is called when a value exists in both maps, and receives a reference to the key as its first argument, the value from the current map as the second argument, and the value from the other map as the third argument. It should return the value to be inserted in the resulting map.
Time: O(n log n)
§Examples
let map1 = ordmap!{1 => 1, 3 => 4};
let map2 = ordmap!{2 => 2, 3 => 5};
let expected = ordmap!{1 => 1, 2 => 2, 3 => 9};
assert_eq!(expected, map1.union_with_key(
map2,
|key, left, right| left + right
));
Sourcepub fn unions<I>(i: I) -> GenericOrdMap<K, V, P>where
I: IntoIterator<Item = GenericOrdMap<K, V, P>>,
pub fn unions<I>(i: I) -> GenericOrdMap<K, V, P>where
I: IntoIterator<Item = GenericOrdMap<K, V, P>>,
Construct the union of a sequence of maps, selecting the value of the leftmost when a key appears in more than one map.
Time: O(n log n)
§Examples
let map1 = ordmap!{1 => 1, 3 => 3};
let map2 = ordmap!{2 => 2};
let expected = ordmap!{1 => 1, 2 => 2, 3 => 3};
assert_eq!(expected, OrdMap::unions(vec![map1, map2]));
Sourcepub fn unions_with<I, F>(i: I, f: F) -> GenericOrdMap<K, V, P>
pub fn unions_with<I, F>(i: I, f: F) -> GenericOrdMap<K, V, P>
Construct the union of a sequence of maps, using a function to decide what to do with the value when a key is in more than one map.
The function is called when a value exists in multiple maps, and receives the value from the current map as its first argument, and the value from the next map as the second. It should return the value to be inserted in the resulting map.
Time: O(n log n)
Sourcepub fn unions_with_key<I, F>(i: I, f: F) -> GenericOrdMap<K, V, P>
pub fn unions_with_key<I, F>(i: I, f: F) -> GenericOrdMap<K, V, P>
Construct the union of a sequence of maps, using a function to decide what to do with the value when a key is in more than one map.
The function is called when a value exists in multiple maps, and receives a reference to the key as its first argument, the value from the current map as the second argument, and the value from the next map as the third argument. It should return the value to be inserted in the resulting map.
Time: O(n log n)
Sourcepub fn difference(self, other: GenericOrdMap<K, V, P>) -> GenericOrdMap<K, V, P>
👎Deprecated since 2.0.1: to avoid conflicting behaviors between std and imbl, the difference
alias for symmetric_difference
will be removed.
pub fn difference(self, other: GenericOrdMap<K, V, P>) -> GenericOrdMap<K, V, P>
difference
alias for symmetric_difference
will be removed.Construct the symmetric difference between two maps by discarding keys which occur in both maps.
This is an alias for the
symmetric_difference
method.
Time: O(n log n)
§Examples
let map1 = ordmap!{1 => 1, 3 => 4};
let map2 = ordmap!{2 => 2, 3 => 5};
let expected = ordmap!{1 => 1, 2 => 2};
assert_eq!(expected, map1.difference(map2));
Sourcepub fn symmetric_difference(
self,
other: GenericOrdMap<K, V, P>,
) -> GenericOrdMap<K, V, P>
pub fn symmetric_difference( self, other: GenericOrdMap<K, V, P>, ) -> GenericOrdMap<K, V, P>
Construct the symmetric difference between two maps by discarding keys which occur in both maps.
Time: O(n log n)
§Examples
let map1 = ordmap!{1 => 1, 3 => 4};
let map2 = ordmap!{2 => 2, 3 => 5};
let expected = ordmap!{1 => 1, 2 => 2};
assert_eq!(expected, map1.symmetric_difference(map2));
Sourcepub fn difference_with<F>(
self,
other: GenericOrdMap<K, V, P>,
f: F,
) -> GenericOrdMap<K, V, P>
👎Deprecated since 2.0.1: to avoid conflicting behaviors between std and imbl, the difference_with
alias for symmetric_difference_with
will be removed.
pub fn difference_with<F>( self, other: GenericOrdMap<K, V, P>, f: F, ) -> GenericOrdMap<K, V, P>
difference_with
alias for symmetric_difference_with
will be removed.Construct the symmetric difference between two maps by using a function to decide what to do if a key occurs in both.
This is an alias for the
symmetric_difference_with
method.
Time: O(n log n)
Sourcepub fn symmetric_difference_with<F>(
self,
other: GenericOrdMap<K, V, P>,
f: F,
) -> GenericOrdMap<K, V, P>
pub fn symmetric_difference_with<F>( self, other: GenericOrdMap<K, V, P>, f: F, ) -> GenericOrdMap<K, V, P>
Construct the symmetric difference between two maps by using a function to decide what to do if a key occurs in both.
Time: O(n log n)
Sourcepub fn difference_with_key<F>(
self,
other: GenericOrdMap<K, V, P>,
f: F,
) -> GenericOrdMap<K, V, P>
👎Deprecated since 2.0.1: to avoid conflicting behaviors between std and imbl, the difference_with_key
alias for symmetric_difference_with_key
will be removed.
pub fn difference_with_key<F>( self, other: GenericOrdMap<K, V, P>, f: F, ) -> GenericOrdMap<K, V, P>
difference_with_key
alias for symmetric_difference_with_key
will be removed.Construct the symmetric difference between two maps by using a function to decide what to do if a key occurs in both. The function receives the key as well as both values.
This is an alias for the
symmetric_difference_with_key
method.
Time: O(n log n)
§Examples
let map1 = ordmap!{1 => 1, 3 => 4};
let map2 = ordmap!{2 => 2, 3 => 5};
let expected = ordmap!{1 => 1, 2 => 2, 3 => 9};
assert_eq!(expected, map1.difference_with_key(
map2,
|key, left, right| Some(left + right)
));
Sourcepub fn symmetric_difference_with_key<F>(
self,
other: GenericOrdMap<K, V, P>,
f: F,
) -> GenericOrdMap<K, V, P>
pub fn symmetric_difference_with_key<F>( self, other: GenericOrdMap<K, V, P>, f: F, ) -> GenericOrdMap<K, V, P>
Construct the symmetric difference between two maps by using a function to decide what to do if a key occurs in both. The function receives the key as well as both values.
Time: O(n log n)
§Examples
let map1 = ordmap!{1 => 1, 3 => 4};
let map2 = ordmap!{2 => 2, 3 => 5};
let expected = ordmap!{1 => 1, 2 => 2, 3 => 9};
assert_eq!(expected, map1.symmetric_difference_with_key(
map2,
|key, left, right| Some(left + right)
));
Sourcepub fn relative_complement(
self,
other: GenericOrdMap<K, V, P>,
) -> GenericOrdMap<K, V, P>
pub fn relative_complement( self, other: GenericOrdMap<K, V, P>, ) -> GenericOrdMap<K, V, P>
Construct the relative complement between two maps by discarding keys
which occur in other
.
Time: O(m log n) where m is the size of the other map
§Examples
let map1 = ordmap!{1 => 1, 3 => 4};
let map2 = ordmap!{2 => 2, 3 => 5};
let expected = ordmap!{1 => 1};
assert_eq!(expected, map1.relative_complement(map2));
Sourcepub fn intersection(
self,
other: GenericOrdMap<K, V, P>,
) -> GenericOrdMap<K, V, P>
pub fn intersection( self, other: GenericOrdMap<K, V, P>, ) -> GenericOrdMap<K, V, P>
Construct the intersection of two maps, keeping the values from the current map.
Time: O(n log n)
§Examples
let map1 = ordmap!{1 => 1, 2 => 2};
let map2 = ordmap!{2 => 3, 3 => 4};
let expected = ordmap!{2 => 2};
assert_eq!(expected, map1.intersection(map2));
Sourcepub fn intersection_with<B, C, F, P2, P3>(
self,
other: GenericOrdMap<K, B, P2>,
f: F,
) -> GenericOrdMap<K, C, P3>
pub fn intersection_with<B, C, F, P2, P3>( self, other: GenericOrdMap<K, B, P2>, f: F, ) -> GenericOrdMap<K, C, P3>
Construct the intersection of two maps, calling a function with both values for each key and using the result as the value for the key.
Time: O(n log n)
Sourcepub fn intersection_with_key<B, C, F, P2, P3>(
self,
other: GenericOrdMap<K, B, P2>,
f: F,
) -> GenericOrdMap<K, C, P3>
pub fn intersection_with_key<B, C, F, P2, P3>( self, other: GenericOrdMap<K, B, P2>, f: F, ) -> GenericOrdMap<K, C, P3>
Construct the intersection of two maps, calling a function with the key and both values for each key and using the result as the value for the key.
Time: O(n log n)
§Examples
let map1 = ordmap!{1 => 1, 2 => 2};
let map2 = ordmap!{2 => 3, 3 => 4};
let expected = ordmap!{2 => 5};
assert_eq!(expected, map1.intersection_with_key(
map2,
|key, left, right| left + right
));
Sourcepub fn split<BK>(
&self,
split: &BK,
) -> (GenericOrdMap<K, V, P>, GenericOrdMap<K, V, P>)
pub fn split<BK>( &self, split: &BK, ) -> (GenericOrdMap<K, V, P>, GenericOrdMap<K, V, P>)
Split a map into two, with the left hand map containing keys
which are smaller than split
, and the right hand map
containing keys which are larger than split
.
The split
mapping is discarded.
Sourcepub fn split_lookup<BK>(
&self,
split: &BK,
) -> (GenericOrdMap<K, V, P>, Option<V>, GenericOrdMap<K, V, P>)
pub fn split_lookup<BK>( &self, split: &BK, ) -> (GenericOrdMap<K, V, P>, Option<V>, GenericOrdMap<K, V, P>)
Split a map into two, with the left hand map containing keys
which are smaller than split
, and the right hand map
containing keys which are larger than split
.
Returns both the two maps and the value of split
.
Sourcepub fn take(&self, n: usize) -> GenericOrdMap<K, V, P>
pub fn take(&self, n: usize) -> GenericOrdMap<K, V, P>
Construct a map with only the n
smallest keys from a given
map.
Sourcepub fn skip(&self, n: usize) -> GenericOrdMap<K, V, P>
pub fn skip(&self, n: usize) -> GenericOrdMap<K, V, P>
Construct a map with the n
smallest keys removed from a
given map.
Sourcepub fn without_min(&self) -> (Option<V>, GenericOrdMap<K, V, P>)
pub fn without_min(&self) -> (Option<V>, GenericOrdMap<K, V, P>)
Remove the smallest key from a map, and return its value as well as the updated map.
Sourcepub fn without_min_with_key(&self) -> (Option<(K, V)>, GenericOrdMap<K, V, P>)
pub fn without_min_with_key(&self) -> (Option<(K, V)>, GenericOrdMap<K, V, P>)
Remove the smallest key from a map, and return that key, its value as well as the updated map.
Sourcepub fn without_max(&self) -> (Option<V>, GenericOrdMap<K, V, P>)
pub fn without_max(&self) -> (Option<V>, GenericOrdMap<K, V, P>)
Remove the largest key from a map, and return its value as well as the updated map.
Sourcepub fn without_max_with_key(&self) -> (Option<(K, V)>, GenericOrdMap<K, V, P>)
pub fn without_max_with_key(&self) -> (Option<(K, V)>, GenericOrdMap<K, V, P>)
Remove the largest key from a map, and return that key, its value as well as the updated map.
Trait Implementations§
Source§impl<K, V, P> Add for &GenericOrdMap<K, V, P>
impl<K, V, P> Add for &GenericOrdMap<K, V, P>
Source§type Output = GenericOrdMap<K, V, P>
type Output = GenericOrdMap<K, V, P>
+
operator.Source§fn add(
self,
other: &GenericOrdMap<K, V, P>,
) -> <&GenericOrdMap<K, V, P> as Add>::Output
fn add( self, other: &GenericOrdMap<K, V, P>, ) -> <&GenericOrdMap<K, V, P> as Add>::Output
+
operation. Read moreSource§impl<K, V, P> Add for GenericOrdMap<K, V, P>
impl<K, V, P> Add for GenericOrdMap<K, V, P>
Source§type Output = GenericOrdMap<K, V, P>
type Output = GenericOrdMap<K, V, P>
+
operator.Source§fn add(
self,
other: GenericOrdMap<K, V, P>,
) -> <GenericOrdMap<K, V, P> as Add>::Output
fn add( self, other: GenericOrdMap<K, V, P>, ) -> <GenericOrdMap<K, V, P> as Add>::Output
+
operation. Read moreSource§impl<K, V, P> AsRef<GenericOrdMap<K, V, P>> for GenericOrdMap<K, V, P>where
P: SharedPointerKind,
impl<K, V, P> AsRef<GenericOrdMap<K, V, P>> for GenericOrdMap<K, V, P>where
P: SharedPointerKind,
Source§fn as_ref(&self) -> &GenericOrdMap<K, V, P>
fn as_ref(&self) -> &GenericOrdMap<K, V, P>
Source§impl<K, V, P> Clone for GenericOrdMap<K, V, P>where
P: SharedPointerKind,
impl<K, V, P> Clone for GenericOrdMap<K, V, P>where
P: SharedPointerKind,
Source§fn clone(&self) -> GenericOrdMap<K, V, P>
fn clone(&self) -> GenericOrdMap<K, V, P>
Clone a map.
Time: O(1)
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<K, V, P> Debug for GenericOrdMap<K, V, P>
impl<K, V, P> Debug for GenericOrdMap<K, V, P>
Source§impl<K, V, P> Default for GenericOrdMap<K, V, P>where
P: SharedPointerKind,
impl<K, V, P> Default for GenericOrdMap<K, V, P>where
P: SharedPointerKind,
Source§fn default() -> GenericOrdMap<K, V, P>
fn default() -> GenericOrdMap<K, V, P>
Source§impl<'de, K, V, P> Deserialize<'de> for GenericOrdMap<K, V, P>
impl<'de, K, V, P> Deserialize<'de> for GenericOrdMap<K, V, P>
Source§fn deserialize<D>(
des: D,
) -> Result<GenericOrdMap<K, V, P>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
des: D,
) -> Result<GenericOrdMap<K, V, P>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<K, V, RK, RV, P> Extend<(RK, RV)> for GenericOrdMap<K, V, P>
impl<K, V, RK, RV, P> Extend<(RK, RV)> for GenericOrdMap<K, V, P>
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (RK, RV)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (RK, RV)>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a, K, V, RK, RV, OK, OV, P> From<&'a [(RK, RV)]> for GenericOrdMap<K, V, P>
impl<'a, K, V, RK, RV, OK, OV, P> From<&'a [(RK, RV)]> for GenericOrdMap<K, V, P>
Source§fn from(m: &'a [(RK, RV)]) -> GenericOrdMap<K, V, P>
fn from(m: &'a [(RK, RV)]) -> GenericOrdMap<K, V, P>
Source§impl<'a, K, V, RK, RV, OK, OV, P> From<&'a BTreeMap<RK, RV>> for GenericOrdMap<K, V, P>
impl<'a, K, V, RK, RV, OK, OV, P> From<&'a BTreeMap<RK, RV>> for GenericOrdMap<K, V, P>
Source§fn from(m: &'a BTreeMap<RK, RV>) -> GenericOrdMap<K, V, P>
fn from(m: &'a BTreeMap<RK, RV>) -> GenericOrdMap<K, V, P>
Source§impl<'a, K, V, S, P1, P2> From<&'a GenericHashMap<K, V, S, P2>> for GenericOrdMap<K, V, P1>where
K: Ord + Hash + Eq + Clone,
V: Clone,
S: BuildHasher + Clone,
P1: SharedPointerKind,
P2: SharedPointerKind,
impl<'a, K, V, S, P1, P2> From<&'a GenericHashMap<K, V, S, P2>> for GenericOrdMap<K, V, P1>where
K: Ord + Hash + Eq + Clone,
V: Clone,
S: BuildHasher + Clone,
P1: SharedPointerKind,
P2: SharedPointerKind,
Source§fn from(m: &'a GenericHashMap<K, V, S, P2>) -> GenericOrdMap<K, V, P1>
fn from(m: &'a GenericHashMap<K, V, S, P2>) -> GenericOrdMap<K, V, P1>
Source§impl<K, V, OK, OV, P1, P2> From<&GenericOrdMap<&K, &V, P2>> for GenericOrdMap<OK, OV, P1>
impl<K, V, OK, OV, P1, P2> From<&GenericOrdMap<&K, &V, P2>> for GenericOrdMap<OK, OV, P1>
Source§fn from(m: &GenericOrdMap<&K, &V, P2>) -> GenericOrdMap<OK, OV, P1>
fn from(m: &GenericOrdMap<&K, &V, P2>) -> GenericOrdMap<OK, OV, P1>
Source§impl<'a, K, V, OK, OV, RK, RV, P> From<&'a HashMap<RK, RV>> for GenericOrdMap<K, V, P>
impl<'a, K, V, OK, OV, RK, RV, P> From<&'a HashMap<RK, RV>> for GenericOrdMap<K, V, P>
Source§fn from(m: &'a HashMap<RK, RV>) -> GenericOrdMap<K, V, P>
fn from(m: &'a HashMap<RK, RV>) -> GenericOrdMap<K, V, P>
Source§impl<K, V, RK, RV, P> From<BTreeMap<RK, RV>> for GenericOrdMap<K, V, P>
impl<K, V, RK, RV, P> From<BTreeMap<RK, RV>> for GenericOrdMap<K, V, P>
Source§fn from(m: BTreeMap<RK, RV>) -> GenericOrdMap<K, V, P>
fn from(m: BTreeMap<RK, RV>) -> GenericOrdMap<K, V, P>
Source§impl<K, V, S, P1, P2> From<GenericHashMap<K, V, S, P2>> for GenericOrdMap<K, V, P1>where
K: Ord + Hash + Eq + Clone,
V: Clone,
S: BuildHasher + Clone,
P1: SharedPointerKind,
P2: SharedPointerKind,
impl<K, V, S, P1, P2> From<GenericHashMap<K, V, S, P2>> for GenericOrdMap<K, V, P1>where
K: Ord + Hash + Eq + Clone,
V: Clone,
S: BuildHasher + Clone,
P1: SharedPointerKind,
P2: SharedPointerKind,
Source§fn from(m: GenericHashMap<K, V, S, P2>) -> GenericOrdMap<K, V, P1>
fn from(m: GenericHashMap<K, V, S, P2>) -> GenericOrdMap<K, V, P1>
Source§impl<K, V, RK, RV, P> From<HashMap<RK, RV>> for GenericOrdMap<K, V, P>
impl<K, V, RK, RV, P> From<HashMap<RK, RV>> for GenericOrdMap<K, V, P>
Source§fn from(m: HashMap<RK, RV>) -> GenericOrdMap<K, V, P>
fn from(m: HashMap<RK, RV>) -> GenericOrdMap<K, V, P>
Source§impl<K, V, RK, RV, P> FromIterator<(RK, RV)> for GenericOrdMap<K, V, P>
impl<K, V, RK, RV, P> FromIterator<(RK, RV)> for GenericOrdMap<K, V, P>
Source§fn from_iter<T>(i: T) -> GenericOrdMap<K, V, P>where
T: IntoIterator<Item = (RK, RV)>,
fn from_iter<T>(i: T) -> GenericOrdMap<K, V, P>where
T: IntoIterator<Item = (RK, RV)>,
Source§impl<K, V, P> Hash for GenericOrdMap<K, V, P>
impl<K, V, P> Hash for GenericOrdMap<K, V, P>
Source§impl<BK, K, V, P> Index<&BK> for GenericOrdMap<K, V, P>
impl<BK, K, V, P> Index<&BK> for GenericOrdMap<K, V, P>
Source§impl<BK, K, V, P> IndexMut<&BK> for GenericOrdMap<K, V, P>
impl<BK, K, V, P> IndexMut<&BK> for GenericOrdMap<K, V, P>
Source§impl<'a, K, V, P> IntoIterator for &'a GenericOrdMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
impl<'a, K, V, P> IntoIterator for &'a GenericOrdMap<K, V, P>where
K: Ord,
P: SharedPointerKind,
Source§impl<K, V, P> IntoIterator for GenericOrdMap<K, V, P>
impl<K, V, P> IntoIterator for GenericOrdMap<K, V, P>
Source§type IntoIter = ConsumingIter<K, V, P>
type IntoIter = ConsumingIter<K, V, P>
Source§fn into_iter(self) -> <GenericOrdMap<K, V, P> as IntoIterator>::IntoIter
fn into_iter(self) -> <GenericOrdMap<K, V, P> as IntoIterator>::IntoIter
Source§impl<K, V, P> Ord for GenericOrdMap<K, V, P>
impl<K, V, P> Ord for GenericOrdMap<K, V, P>
Source§fn cmp(&self, other: &GenericOrdMap<K, V, P>) -> Ordering
fn cmp(&self, other: &GenericOrdMap<K, V, P>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<K, V, P> PartialEq for GenericOrdMap<K, V, P>
impl<K, V, P> PartialEq for GenericOrdMap<K, V, P>
Source§impl<K, V, P> PartialOrd for GenericOrdMap<K, V, P>
impl<K, V, P> PartialOrd for GenericOrdMap<K, V, P>
Source§impl<K, V, P> Serialize for GenericOrdMap<K, V, P>
impl<K, V, P> Serialize for GenericOrdMap<K, V, P>
Source§fn serialize<S>(
&self,
ser: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
ser: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<K, V, P> Sum for GenericOrdMap<K, V, P>
impl<K, V, P> Sum for GenericOrdMap<K, V, P>
Source§fn sum<I>(it: I) -> GenericOrdMap<K, V, P>where
I: Iterator<Item = GenericOrdMap<K, V, P>>,
fn sum<I>(it: I) -> GenericOrdMap<K, V, P>where
I: Iterator<Item = GenericOrdMap<K, V, P>>,
Self
from the elements by “summing up”
the items.impl<K, V, P> Eq for GenericOrdMap<K, V, P>
Auto Trait Implementations§
impl<K, V, P> Freeze for GenericOrdMap<K, V, P>where
P: Freeze,
impl<K, V, P> RefUnwindSafe for GenericOrdMap<K, V, P>
impl<K, V, P> Send for GenericOrdMap<K, V, P>
impl<K, V, P> Sync for GenericOrdMap<K, V, P>
impl<K, V, P> Unpin for GenericOrdMap<K, V, P>
impl<K, V, P> UnwindSafe for GenericOrdMap<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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