pub struct MapDomain<K: Ord, V: AbstractDomain>(_);

Implementations§

source§

impl<K: Ord + Clone, V: AbstractDomain + Clone> MapDomain<K, V>

source

pub fn singleton(k: K, v: V) -> MapDomain<K, V>

Construct a singleton map.

source

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>

source

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

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

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 len(&self) -> usize

Get the size of a map.

Time: O(1)

Examples
assert_eq!(3, ordmap!{
  1 => 11,
  2 => 22,
  3 => 33
}.len());

pub fn clear(&mut self)

Discard all elements from the map.

This leaves you with an empty map, and all elements that were previously inside it are dropped.

Time: O(n)

Examples
let mut map = ordmap![1=>1, 2=>2, 3=>3];
map.clear();
assert!(map.is_empty());

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)>

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>

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,

Create an iterator over a range of key/value pairs.

pub fn keys(&self) -> Keys<'_, K, V>

Get an iterator over a map’s keys.

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>

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>,

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>,

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>,

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>,

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>,

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>>,

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>>,

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>>,

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>>,

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>,

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>,

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>,

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>

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>,

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>,

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>

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>,

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>,

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>,

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>,

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>,

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>,

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>

Construct a map with only the n smallest keys from a given map.

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>)

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>)

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>)

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>)

Remove the largest key from a map, and return that key, its value as well as the updated map.

pub fn entry(&mut self, key: K) -> Entry<'_, K, V>

Get the Entry for a key in the map for in-place manipulation.

Time: O(log n)

Trait Implementations§

source§

impl<K: Ord + Clone, V: AbstractDomain + Clone> AbstractDomain for MapDomain<K, V>

source§

fn join(&mut self, other: &Self) -> JoinResult

source§

impl<K: Ord + Clone, V: AbstractDomain + Clone> AsRef<OrdMap<K, V>> for MapDomain<K, V>

source§

fn as_ref(&self) -> &OrdMap<K, V>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<K: Ord + Clone, V: AbstractDomain + Clone> Borrow<OrdMap<K, V>> for MapDomain<K, V>

source§

fn borrow(&self) -> &OrdMap<K, V>

Immutably borrows from an owned value. Read more
source§

impl<K: Clone + Ord, V: Clone + AbstractDomain> Clone for MapDomain<K, V>

source§

fn clone(&self) -> MapDomain<K, V>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K: Ord + Clone + Debug, V: AbstractDomain + Clone + Debug> Debug for MapDomain<K, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: Ord + Clone, V: AbstractDomain + Clone> Default for MapDomain<K, V>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<K: Ord + Clone, V: AbstractDomain + Clone> Deref for MapDomain<K, V>

§

type Target = OrdMap<K, V>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<K: Ord + Clone, V: AbstractDomain + Clone> DerefMut for MapDomain<K, V>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<K: Ord + Clone, V: AbstractDomain + Clone> From<BTreeMap<K, V, Global>> for MapDomain<K, V>

source§

fn from(m: BTreeMap<K, V>) -> Self

Converts to this type from the input type.
source§

impl<K: Ord + Clone, V: AbstractDomain + Clone> From<OrdMap<K, V>> for MapDomain<K, V>

source§

fn from(ord_map: OrdMap<K, V>) -> Self

Converts to this type from the input type.
source§

impl<K: Ord + Clone, V: AbstractDomain + Clone> FromIterator<(K, V)> for MapDomain<K, V>

source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<K: Ord + Clone, V: AbstractDomain + Clone> IntoIterator for MapDomain<K, V>

§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = ConsumingIter<(K, V)>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K: Ord + Ord, V: Ord + AbstractDomain> Ord for MapDomain<K, V>

source§

fn cmp(&self, other: &MapDomain<K, V>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<K: PartialEq + Ord, V: PartialEq + AbstractDomain> PartialEq<MapDomain<K, V>> for MapDomain<K, V>

source§

fn eq(&self, other: &MapDomain<K, V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K: PartialOrd + Ord, V: PartialOrd + AbstractDomain> PartialOrd<MapDomain<K, V>> for MapDomain<K, V>

source§

fn partial_cmp(&self, other: &MapDomain<K, V>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<K: Eq + Ord, V: Eq + AbstractDomain> Eq for MapDomain<K, V>

source§

impl<K: Ord, V: AbstractDomain> StructuralEq for MapDomain<K, V>

source§

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<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V