Struct im::ordmap::OrdMap [] [src]

pub struct OrdMap<K, V> { /* fields omitted */ }

Ordered Map

An immutable ordered map implemented as a B-tree.

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.

Methods

impl<K, V> OrdMap<K, V>
[src]

[src]

Construct an empty map.

[src]

Construct a map with a single mapping.

Examples

let map = OrdMap::singleton(123, "onetwothree");
assert_eq!(
  map.get(&123),
  Some(Arc::new("onetwothree"))
);

[src]

Test whether a map is empty.

Time: O(1)

Examples

assert!(
  !ordmap!{1 => 2}.is_empty()
);
assert!(
  OrdMap::<i32, i32>::new().is_empty()
);

[src]

Get the size of a map.

Time: O(1)

Examples

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

[src]

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((Arc::new(3), Arc::new(33))), ordmap!{
  1 => 11,
  2 => 22,
  3 => 33
}.get_max());

[src]

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((Arc::new(1), Arc::new(11))), ordmap!{
  1 => 11,
  2 => 22,
  3 => 33
}.get_min());

impl<K: Ord, V> OrdMap<K, V>
[src]

[src]

Get an iterator over the key/value pairs of a map.

Important traits for Keys<K, V>
[src]

Get an iterator over a map's keys.

Important traits for Values<K, V>
[src]

Get an iterator over a map's values.

[src]

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(Arc::new("lol"))
);

[src]

Get the value for a key from a map, or a default value if the key isn't in the map.

Time: O(log n)

Examples

let map = ordmap!{123 => "lol"};
assert_eq!(
  map.get_or(&123, "hi"),
  Arc::new("lol")
);
assert_eq!(
  map.get_or(&321, "hi"),
  Arc::new("hi")
);

[src]

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

[src]

Construct a new map by inserting a key/value mapping into a map.

This is an alias for insert.

[src]

Insert a key/value mapping into a map, mutating it in place when it is safe to do so.

This is an alias for insert_mut.

[src]

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.insert(123, "123"),
  ordmap!{123 => "123"}
);

[src]

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_mut(123, "123");
map.insert_mut(456, "456");
assert_eq!(
  map,
  ordmap!{123 => "123", 456 => "456"}
);

[src]

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)

[src]

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)

[src]

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)

[src]

Update the value for a given key by calling a function with the current value and overwriting it with the function's return value.

Time: O(log n)

[src]

Update the value for a given key by calling a function with the key and the current value and overwriting it with the function's return value.

Time: O(log n)

[src]

Update the value for a given key by calling a function with the key and the current value and overwriting it with the function's return value.

If the key was not in the map, the function is never called and the map is left unchanged.

Return a tuple of the old value, if there was one, and the new map.

Time: O(log n)

[src]

Update the value for a given key by calling a function with the current value and overwriting it with the function's return value.

This is like the update method, except with more control: 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)

[src]

Remove a key/value pair from a map, if it exists.

Time: O(log n)

[src]

Remove a key/value mapping from a map if it exists, mutating it in place when it is safe to do so.

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.

Time: O(log n)

Examples

let mut map = ordmap!{123 => "123", 456 => "456"};
map.remove_mut(&123);
map.remove_mut(&456);
assert!(map.is_empty());

[src]

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)

[src]

Remove a key/value pair from a map, if it exists, and return the removed value.

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.

Time: O(log n)

[src]

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)

[src]

Remove a key/value pair from a map, if it exists, and return the removed key and value.

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.

Time: O(log n)

[src]

Construct the union of two maps, keeping the values in the current map when keys exist in both maps.

[src]

Construct the union of two maps, using a function to decide what to do with the value when a key is in both maps.

[src]

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 receives the key as well as both values.

[src]

Construct the union of a sequence of maps, selecting the value of the leftmost when a key appears in more than one map.

[src]

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.

[src]

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 receives the key as well as both values.

[src]

Construct the difference between two maps by discarding keys which occur in both maps.

[src]

Construct the difference between two maps by using a function to decide what to do if a key occurs in both.

[src]

Construct the 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.

[src]

Construct the intersection of two maps, keeping the values from the current map.

[src]

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.

[src]

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.

[src]

Merge two maps.

First, we call the combine function for each key/value pair which exists in both maps, updating the value or discarding it according to the function's return value.

The only1 and only2 functions are called with the key/value pairs which are only in the first and the second list respectively. The results of these are then merged with the result of the first operation.

[src]

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.

[src]

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.

[src]

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.

[src]

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.

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

Discard the smallest key from a map, returning the updated map.

[src]

Discard the largest key from a map, returning the updated map.

[src]

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.

[src]

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.

Trait Implementations

impl<K, V> Clone for OrdMap<K, V>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<K: Ord + PartialEq, V: PartialEq> PartialEq for OrdMap<K, V>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<K: Ord + Eq, V: Eq> Eq for OrdMap<K, V>
[src]

impl<K: PartialOrd, V: PartialOrd> PartialOrd for OrdMap<K, V> where
    K: Ord
[src]

[src]

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

1.0.0
[src]

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

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

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

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 OrdMap<K, V>
[src]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl<K: Ord + Hash, V: Hash> Hash for OrdMap<K, V>
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<K, V> Default for OrdMap<K, V>
[src]

[src]

Returns the "default value" for a type. Read more

impl<'a, K: Ord, V> Add for &'a OrdMap<K, V>
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl<K: Ord, V> Add for OrdMap<K, V>
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl<K, V> Sum for OrdMap<K, V> where
    K: Ord
[src]

[src]

Method which takes an iterator and generates Self from the elements by "summing up" the items. Read more

impl<K, V, RK, RV> Extend<(RK, RV)> for OrdMap<K, V> where
    K: Ord,
    RK: Shared<K>,
    RV: Shared<V>, 
[src]

[src]

Extends a collection with the contents of an iterator. Read more

impl<'a, K, V> Index<&'a K> for OrdMap<K, V> where
    K: Ord
[src]

The returned type after indexing.

[src]

Performs the indexing (container[index]) operation.

impl<'a, K, V> IndexMut<&'a K> for OrdMap<K, V> where
    K: Ord,
    V: Clone
[src]

[src]

Performs the mutable indexing (container[index]) operation.

impl<K: Debug, V: Debug> Debug for OrdMap<K, V> where
    K: Ord
[src]

[src]

Formats the value using the given formatter. Read more

impl<K: Ord, V, RK, RV> FromIterator<(RK, RV)> for OrdMap<K, V> where
    RK: Shared<K>,
    RV: Shared<V>, 
[src]

[src]

Creates a value from an iterator. Read more

impl<'a, K, V> IntoIterator for &'a OrdMap<K, V> where
    K: Ord
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<K, V> IntoIterator for OrdMap<K, V> where
    K: Ord
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<K, V> AsRef<OrdMap<K, V>> for OrdMap<K, V>
[src]

[src]

Performs the conversion.

impl<'a, K: Ord, V: Clone, RK, RV> From<&'a [(RK, RV)]> for OrdMap<K, V> where
    &'a RK: Shared<K>,
    &'a RV: Shared<V>, 
[src]

[src]

Performs the conversion.

impl<K: Ord, V, RK, RV> From<Vec<(RK, RV)>> for OrdMap<K, V> where
    RK: Shared<K>,
    RV: Shared<V>, 
[src]

[src]

Performs the conversion.

impl<'a, K: Ord, V, RK, RV> From<&'a Vec<(RK, RV)>> for OrdMap<K, V> where
    &'a RK: Shared<K>,
    &'a RV: Shared<V>, 
[src]

[src]

Performs the conversion.

impl<K: Ord, V, RK: Eq + Hash, RV> From<HashMap<RK, RV>> for OrdMap<K, V> where
    RK: Shared<K>,
    RV: Shared<V>, 
[src]

[src]

Performs the conversion.

impl<'a, K: Ord, V, RK: Eq + Hash, RV> From<&'a HashMap<RK, RV>> for OrdMap<K, V> where
    &'a RK: Shared<K>,
    &'a RV: Shared<V>, 
[src]

[src]

Performs the conversion.

impl<K: Ord, V, RK, RV> From<BTreeMap<RK, RV>> for OrdMap<K, V> where
    RK: Shared<K>,
    RV: Shared<V>, 
[src]

[src]

Performs the conversion.

impl<'a, K: Ord, V, RK, RV> From<&'a BTreeMap<RK, RV>> for OrdMap<K, V> where
    &'a RK: Shared<K>,
    &'a RV: Shared<V>, 
[src]

[src]

Performs the conversion.

impl<K: Ord + Hash + Eq, V, S: BuildHasher> From<HashMap<K, V, S>> for OrdMap<K, V>
[src]

[src]

Performs the conversion.

impl<'a, K: Ord + Hash + Eq, V, S: BuildHasher> From<&'a HashMap<K, V, S>> for OrdMap<K, V>
[src]

[src]

Performs the conversion.

Auto Trait Implementations

impl<K, V> Send for OrdMap<K, V> where
    K: Send + Sync,
    V: Send + Sync

impl<K, V> Sync for OrdMap<K, V> where
    K: Send + Sync,
    V: Send + Sync