Struct immutable_chunkmap::rc::map::Map[][src]

pub struct Map<K: Ord + Clone + Debug, V: Clone + Debug> { /* fields omitted */ }

This Map uses a similar strategy to BTreeMap to ensure cache efficient performance on modern hardware while still providing log(N) get, insert, and remove operations.

Examples

use std::string::String;
use self::immutable_chunkmap::rc::map::Map;

let m =
   Map::new()
   .insert(String::from("1"), 1).0
   .insert(String::from("2"), 2).0
   .insert(String::from("3"), 3).0;

assert_eq!(m.get("1"), Option::Some(&1));
assert_eq!(m.get("2"), Option::Some(&2));
assert_eq!(m.get("3"), Option::Some(&3));
assert_eq!(m.get("4"), Option::None);

for (k, v) in &m {
  println!("key {}, val: {}", k, v)
}

Methods

impl<K, V> Map<K, V> where
    K: Ord + Clone + Debug,
    V: Clone + Debug
[src]

Create a new empty map

This will insert many elements at once, and is potentially a lot faster than inserting one by one, especially if the data is sorted. It is just a wrapper around the more general update_many method.

#Examples

 use self::immutable_chunkmap::rc::map::Map;

 let mut v = vec![(1, 3), (10, 1), (-12, 2), (44, 0), (50, -1)];
 v.sort_unstable_by_key(|&(k, _)| k);

 let m = Map::new().insert_many(v.iter().map(|(k, v)| (*k, *v)));

 for (k, v) in &v {
   assert_eq!(m.get(k), Option::Some(v))
 }

This method updates multiple bindings in one call. Given an iterator of an arbitrary type D, a key extraction function on D, an update function taking D, the current binding in the map, if any, and producing the new binding, if any, this method will produce a new map with updated bindings of many elements at once. It will skip intermediate node allocations where possible. If the data in elts is sorted, it will be able to skip many more intermediate allocations, and can produce a speedup of about 10x compared to inserting/updating one by one. It should always be faster than inserting elements one by one, even with random unsorted keys.

This method will panic if kf, and uf return inconsistent keys.

#Examples

use self::immutable_chunkmap::rc::map::Map;

let m = Map::new().insert_many((0..4).map(|k| (k, k)));
let m = m.update_many(
    (0..4).map(|x| (x, ())),
    &mut |_, (), cur| cur.map(|c| c + 1)
);
assert_eq!(
    m.into_iter().map(|(k, v)| (*k, *v)).collect::<Vec<_>>(),
    vec![(0, 1), (1, 2), (2, 3), (3, 4)]
);

return a new map with (k, v) inserted into it. If k already exists in the old map, the old binding will be returned, and the new map will contain the new binding. In fact this method is just a wrapper around update.

return a new map with the binding for k updated to the result of f. If f returns None, the binding will be removed from the new map, otherwise it will be inserted. This function is more efficient than calling get and then insert, since it makes only one tree traversal instead of two. This method runs in log(N) time and space where N is the size of the map.

Examples

use self::immutable_chunkmap::rc::map::Map;

let (m, _) = Map::new().update(0, 0, &mut |k, d, _| Some(d));
assert_eq!(m.get(&0), Some(&0));

let (m, _) = m.update(0, (), &mut |_, (), v| v.map(|v| v + 1));
assert_eq!(m.get(&0), Some(&1));

lookup the mapping for k. If it doesn't exist return None. Runs in log(N) time and constant space. where N is the size of the map.

return a new map with the mapping under k removed. Runs in log(N) time and log(N) space, where N is the size of the map

get the number of elements in the map O(1) time and space

return an iterator over the subset of elements in the map that are within the specified range.

The returned iterator runs in O(log(N) + M) time, and constant space. N is the number of elements in the tree, and M is the number of elements you examine.

if lbound >= ubound the returned iterator will be empty

Trait Implementations

impl<K: Clone + Ord + Clone + Debug, V: Clone + Clone + Debug> Clone for Map<K, V>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<K: Debug + Ord + Clone + Debug, V: Debug + Clone + Debug> Debug for Map<K, V>
[src]

Formats the value using the given formatter. Read more

impl<K: PartialEq + Ord + Clone + Debug, V: PartialEq + Clone + Debug> PartialEq for Map<K, V>
[src]

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

This method tests for !=.

impl<K: Eq + Ord + Clone + Debug, V: Eq + Clone + Debug> Eq for Map<K, V>
[src]

impl<K: PartialOrd + Ord + Clone + Debug, V: PartialOrd + Clone + Debug> PartialOrd for Map<K, V>
[src]

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

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

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

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

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

impl<K: Ord + Ord + Clone + Debug, V: Ord + Clone + Debug> Ord for Map<K, V>
[src]

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

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl<'a, K, V> IntoIterator for &'a Map<K, V> where
    K: 'a + Borrow<K> + Ord + Clone + Debug,
    V: 'a + Clone + Debug
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Auto Trait Implementations

impl<K, V> !Send for Map<K, V>

impl<K, V> !Sync for Map<K, V>