Struct bytecode::dataflow_domains::MapDomain
source · pub struct MapDomain<K: Ord, V: AbstractDomain>(_);
Implementations§
source§impl<K: Ord + Clone, V: AbstractDomain + Clone> MapDomain<K, V>
impl<K: Ord + Clone, V: AbstractDomain + Clone> MapDomain<K, V>
sourcepub fn insert_join(&mut self, k: K, v: V) -> JoinResult
pub fn insert_join(&mut self, k: K, v: V) -> JoinResult
Join v
with self[k] if k
is bound, insert v
otherwise
source§impl<K: Ord + Clone, V: AbstractDomain + Clone + PartialEq> MapDomain<K, V>
impl<K: Ord + Clone, V: AbstractDomain + Clone + PartialEq> MapDomain<K, V>
sourcepub fn update_values(&mut self, f: impl FnMut(&mut V))
pub fn update_values(&mut self, f: impl FnMut(&mut V))
Updates the values in the range of the map using the given function. Notice
that with other kind of map representations we would use iter_mut
for this,
but this is not available in OrdMap for obvious reasons (because entries are shared),
so we need to use this pattern here instead.
Methods from Deref<Target = OrdMap<K, V>>§
pub 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()
);
pub fn ptr_eq(&self, other: &OrdMap<K, V>) -> bool
pub fn ptr_eq(&self, other: &OrdMap<K, V>) -> 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)
pub 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());
pub 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());
pub fn iter(&self) -> Iter<'_, K, V>
pub fn iter(&self) -> Iter<'_, K, V>
Get an iterator over the key/value pairs of a map.
pub fn range<R, BK>(&self, range: R) -> Iter<'_, K, V>where
R: RangeBounds<BK>,
K: Borrow<BK>,
BK: Ord + ?Sized,
pub fn range<R, BK>(&self, range: R) -> Iter<'_, K, V>where R: RangeBounds<BK>, K: Borrow<BK>, BK: Ord + ?Sized,
Create an iterator over a range of key/value pairs.
pub fn keys(&self) -> Keys<'_, K, V>
pub fn keys(&self) -> Keys<'_, K, V>
Get an iterator over a map’s keys.
pub fn values(&self) -> Values<'_, K, V>
pub fn values(&self) -> Values<'_, K, V>
Get an iterator over a map’s values.
pub fn diff<'a>(&'a self, other: &'a OrdMap<K, V>) -> DiffIter<'a, K, V>
pub fn diff<'a>(&'a self, other: &'a OrdMap<K, V>) -> DiffIter<'a, K, V>
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 maps, meaning that even very large maps can be compared quickly if most of their structure is shared.
Time: O(n) (where n is the number of unique elements across the two maps, minus the number of elements belonging to nodes shared between them)
pub fn get<BK>(&self, key: &BK) -> Option<&V>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn get<BK>(&self, key: &BK) -> Option<&V>where BK: Ord + ?Sized, K: Borrow<BK>,
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")
);
pub fn get_key_value<BK>(&self, key: &BK) -> Option<(&K, &V)>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn get_key_value<BK>(&self, key: &BK) -> Option<(&K, &V)>where BK: Ord + ?Sized, K: Borrow<BK>,
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"))
);
pub fn get_prev<BK>(&self, key: &BK) -> Option<(&K, &V)>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn get_prev<BK>(&self, key: &BK) -> Option<(&K, &V)>where BK: Ord + ?Sized, K: Borrow<BK>,
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 map = ordmap![1 => 1, 3 => 3, 5 => 5];
assert_eq!(Some((&3, &3)), map.get_prev(&4));
pub fn get_next<BK>(&self, key: &BK) -> Option<(&K, &V)>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn get_next<BK>(&self, key: &BK) -> Option<(&K, &V)>where BK: Ord + ?Sized, K: Borrow<BK>,
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 map = ordmap![1 => 1, 3 => 3, 5 => 5];
assert_eq!(Some((&5, &5)), map.get_next(&4));
pub fn contains_key<BK>(&self, k: &BK) -> boolwhere
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn contains_key<BK>(&self, k: &BK) -> boolwhere BK: Ord + ?Sized, K: Borrow<BK>,
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)
);
pub fn is_submap_by<B, RM, F>(&self, other: RM, cmp: F) -> boolwhere
F: FnMut(&V, &B) -> bool,
RM: Borrow<OrdMap<K, B>>,
pub fn is_submap_by<B, RM, F>(&self, other: RM, cmp: F) -> boolwhere F: FnMut(&V, &B) -> bool, RM: Borrow<OrdMap<K, B>>,
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)
pub fn is_proper_submap_by<B, RM, F>(&self, other: RM, cmp: F) -> boolwhere
F: FnMut(&V, &B) -> bool,
RM: Borrow<OrdMap<K, B>>,
pub fn is_proper_submap_by<B, RM, F>(&self, other: RM, cmp: F) -> boolwhere F: FnMut(&V, &B) -> bool, RM: Borrow<OrdMap<K, B>>,
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)
pub fn is_submap<RM>(&self, other: RM) -> boolwhere
V: PartialEq<V>,
RM: Borrow<OrdMap<K, V>>,
pub fn is_submap<RM>(&self, other: RM) -> boolwhere V: PartialEq<V>, RM: Borrow<OrdMap<K, V>>,
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));
pub fn is_proper_submap<RM>(&self, other: RM) -> boolwhere
V: PartialEq<V>,
RM: Borrow<OrdMap<K, V>>,
pub fn is_proper_submap<RM>(&self, other: RM) -> boolwhere V: PartialEq<V>, RM: Borrow<OrdMap<K, V>>,
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));
pub fn get_mut<BK>(&mut self, key: &BK) -> Option<&mut V>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn get_mut<BK>(&mut self, key: &BK) -> Option<&mut V>where BK: Ord + ?Sized, K: Borrow<BK>,
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")
);
pub fn get_prev_mut<BK>(&mut self, key: &BK) -> Option<(&K, &mut V)>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn get_prev_mut<BK>(&mut self, key: &BK) -> Option<(&K, &mut V)>where BK: Ord + ?Sized, K: Borrow<BK>,
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);
pub fn get_next_mut<BK>(&mut self, key: &BK) -> Option<(&K, &mut V)>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn get_next_mut<BK>(&mut self, key: &BK) -> Option<(&K, &mut V)>where BK: Ord + ?Sized, K: Borrow<BK>,
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);
pub 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"}
);
pub fn remove<BK>(&mut self, k: &BK) -> Option<V>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn remove<BK>(&mut self, k: &BK) -> Option<V>where BK: Ord + ?Sized, K: Borrow<BK>,
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());
pub fn remove_with_key<BK>(&mut self, k: &BK) -> Option<(K, V)>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn remove_with_key<BK>(&mut self, k: &BK) -> Option<(K, V)>where BK: Ord + ?Sized, K: Borrow<BK>,
Remove a key/value pair from a map, if it exists, and return the removed key and value.
Time: O(log n)
pub fn update(&self, key: K, value: V) -> OrdMap<K, V>
pub fn update(&self, key: K, value: V) -> OrdMap<K, 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, the previous value is overwritten.
Time: O(log n)
Examples
let map = ordmap!{};
assert_eq!(
map.update(123, "123"),
ordmap!{123 => "123"}
);
pub fn alter<F>(&self, f: F, k: K) -> OrdMap<K, V>where
F: FnOnce(Option<V>) -> Option<V>,
pub fn alter<F>(&self, f: F, k: K) -> OrdMap<K, V>where F: FnOnce(Option<V>) -> Option<V>,
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)
pub fn without<BK>(&self, k: &BK) -> OrdMap<K, V>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn without<BK>(&self, k: &BK) -> OrdMap<K, V>where BK: Ord + ?Sized, K: Borrow<BK>,
Remove a key/value pair from a map, if it exists.
Time: O(log n)
pub fn extract<BK>(&self, k: &BK) -> Option<(V, OrdMap<K, V>)>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn extract<BK>(&self, k: &BK) -> Option<(V, OrdMap<K, V>)>where BK: Ord + ?Sized, K: Borrow<BK>,
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)
pub fn extract_with_key<BK>(&self, k: &BK) -> Option<(K, V, OrdMap<K, V>)>where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn extract_with_key<BK>(&self, k: &BK) -> Option<(K, V, OrdMap<K, V>)>where BK: Ord + ?Sized, K: Borrow<BK>,
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)
pub fn split<BK>(&self, split: &BK) -> (OrdMap<K, V>, OrdMap<K, V>)where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn split<BK>(&self, split: &BK) -> (OrdMap<K, V>, OrdMap<K, V>)where BK: Ord + ?Sized, K: Borrow<BK>,
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.
pub fn split_lookup<BK>(
&self,
split: &BK
) -> (OrdMap<K, V>, Option<V>, OrdMap<K, V>)where
BK: Ord + ?Sized,
K: Borrow<BK>,
pub fn split_lookup<BK>( &self, split: &BK ) -> (OrdMap<K, V>, Option<V>, OrdMap<K, V>)where BK: Ord + ?Sized, K: Borrow<BK>,
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
.
pub fn take(&self, n: usize) -> OrdMap<K, V>
pub fn take(&self, n: usize) -> OrdMap<K, V>
Construct a map with only the n
smallest keys from a given
map.
pub fn skip(&self, n: usize) -> OrdMap<K, V>
pub fn skip(&self, n: usize) -> OrdMap<K, V>
Construct a map with the n
smallest keys removed from a
given map.
pub fn without_min(&self) -> (Option<V>, OrdMap<K, V>)
pub fn without_min(&self) -> (Option<V>, OrdMap<K, V>)
Remove the smallest key from a map, and return its value as well as the updated map.
pub fn without_min_with_key(&self) -> (Option<(K, V)>, OrdMap<K, V>)
pub fn without_min_with_key(&self) -> (Option<(K, V)>, OrdMap<K, V>)
Remove the smallest key from a map, and return that key, its value as well as the updated map.
pub fn without_max(&self) -> (Option<V>, OrdMap<K, V>)
pub fn without_max(&self) -> (Option<V>, OrdMap<K, V>)
Remove the largest key from a map, and return its value as well as the updated map.
pub fn without_max_with_key(&self) -> (Option<(K, V)>, OrdMap<K, V>)
pub fn without_max_with_key(&self) -> (Option<(K, V)>, OrdMap<K, V>)
Remove the largest key from a map, and return that key, its value as well as the updated map.
Trait Implementations§
source§impl<K: Ord + Clone, V: AbstractDomain + Clone> AbstractDomain for MapDomain<K, V>
impl<K: Ord + Clone, V: AbstractDomain + Clone> AbstractDomain for MapDomain<K, V>
fn join(&mut self, other: &Self) -> JoinResult
source§impl<K: Ord + Clone, V: AbstractDomain + Clone> From<BTreeMap<K, V, Global>> for MapDomain<K, V>
impl<K: Ord + Clone, V: AbstractDomain + Clone> From<BTreeMap<K, V, Global>> for MapDomain<K, V>
source§impl<K: Ord + Clone, V: AbstractDomain + Clone> FromIterator<(K, V)> for MapDomain<K, V>
impl<K: Ord + Clone, V: AbstractDomain + Clone> FromIterator<(K, V)> for MapDomain<K, V>
source§impl<K: Ord + Clone, V: AbstractDomain + Clone> IntoIterator for MapDomain<K, V>
impl<K: Ord + Clone, V: AbstractDomain + Clone> IntoIterator for MapDomain<K, V>
source§impl<K: Ord + Ord, V: Ord + AbstractDomain> Ord for MapDomain<K, V>
impl<K: Ord + Ord, V: Ord + AbstractDomain> Ord for MapDomain<K, V>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl<K: PartialEq + Ord, V: PartialEq + AbstractDomain> PartialEq<MapDomain<K, V>> for MapDomain<K, V>
impl<K: PartialEq + Ord, V: PartialEq + AbstractDomain> PartialEq<MapDomain<K, V>> for MapDomain<K, V>
source§impl<K: PartialOrd + Ord, V: PartialOrd + AbstractDomain> PartialOrd<MapDomain<K, V>> for MapDomain<K, V>
impl<K: PartialOrd + Ord, V: PartialOrd + AbstractDomain> PartialOrd<MapDomain<K, V>> for MapDomain<K, V>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<K: Eq + Ord, V: Eq + AbstractDomain> Eq for MapDomain<K, V>
impl<K: Ord, V: AbstractDomain> StructuralEq for MapDomain<K, V>
impl<K: Ord, V: AbstractDomain> StructuralPartialEq for MapDomain<K, V>
Auto Trait Implementations§
impl<K, V> RefUnwindSafe for MapDomain<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,
impl<K, V> Send for MapDomain<K, V>where K: Send + Sync, V: Send + Sync,
impl<K, V> Sync for MapDomain<K, V>where K: Send + Sync, V: Send + Sync,
impl<K, V> Unpin for MapDomain<K, V>where K: Unpin, V: Unpin,
impl<K, V> UnwindSafe for MapDomain<K, V>where K: UnwindSafe + RefUnwindSafe, V: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.