Struct extended_collections::red_black_tree::RedBlackMap[][src]

pub struct RedBlackMap<T, U> { /* fields omitted */ }

An ordered map implemented using an avl tree.

An avl tree is a self-balancing binary search tree that uses a color bit to ensure that the tree remains approximately balanced during insertions and deletions. heights of two child subtrees of any node differ by at most one.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(0, 1);
map.insert(3, 4);

assert_eq!(map[&0], 1);
assert_eq!(map.get(&1), None);
assert_eq!(map.len(), 2);

assert_eq!(map.min(), Some(&0));
assert_eq!(map.ceil(&2), Some(&3));

map[&0] = 2;
assert_eq!(map.remove(&0), Some((0, 2)));
assert_eq!(map.remove(&1), None);

Methods

impl<T, U> RedBlackMap<T, U>
[src]

Constructs a new, empty RedBlackMap<T, U>.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let map: RedBlackMap<u32, u32> = RedBlackMap::new();

Inserts a key-value pair into the map. If the key already exists in the map, it will return and replace the old key-value pair.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
assert_eq!(map.insert(1, 1), None);
assert_eq!(map.get(&1), Some(&1));
assert_eq!(map.insert(1, 2), Some((1, 1)));
assert_eq!(map.get(&1), Some(&2));

Removes a key-value pair from the map. If the key exists in the map, it will return the associated key-value pair. Otherwise it will return None.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
assert_eq!(map.remove(&1), Some((1, 1)));
assert_eq!(map.remove(&1), None);

Checks if a key exists in the map.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
assert!(!map.contains_key(&0));
assert!(map.contains_key(&1));

Returns an immutable reference to the value associated with a particular key. It will return None if the key does not exist in the map.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
assert_eq!(map.get(&0), None);
assert_eq!(map.get(&1), Some(&1));

Returns a mutable reference to the value associated with a particular key. Returns None if such a key does not exist.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
*map.get_mut(&1).unwrap() = 2;
assert_eq!(map.get(&1), Some(&2));

Returns the number of elements in the map.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
assert_eq!(map.len(), 1);

Returns true if the map is empty.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let map: RedBlackMap<u32, u32> = RedBlackMap::new();
assert!(map.is_empty());

Clears the map, removing all values.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
map.insert(2, 2);
map.clear();
assert_eq!(map.is_empty(), true);

Returns a key in the map that is less than or equal to a particular key. Returns None if such a key does not exist.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
assert_eq!(map.floor(&0), None);
assert_eq!(map.floor(&2), Some(&1));

Returns a key in the map that is greater than or equal to a particular key. Returns None if such a key does not exist.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
assert_eq!(map.ceil(&0), Some(&1));
assert_eq!(map.ceil(&2), None);

Returns the minimum key of the map. Returns None if the map is empty.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
map.insert(3, 3);
assert_eq!(map.min(), Some(&1));

Returns the maximum key of the map. Returns None if the map is empty.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
map.insert(3, 3);
assert_eq!(map.max(), Some(&3));

Returns an iterator over the map. The iterator will yield key-value pairs using in-order traversal.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
map.insert(2, 2);

let mut iterator = map.iter();
assert_eq!(iterator.next(), Some((&1, &1)));
assert_eq!(iterator.next(), Some((&2, &2)));
assert_eq!(iterator.next(), None);

Returns a mutable iterator over the map. The iterator will yield key-value pairs using in-order traversal.

Examples

use extended_collections::red_black_tree::RedBlackMap;

let mut map = RedBlackMap::new();
map.insert(1, 1);
map.insert(2, 2);

for (key, value) in &mut map {
    *value += 1;
}

let mut iterator = map.iter_mut();
assert_eq!(iterator.next(), Some((&1, &mut 2)));
assert_eq!(iterator.next(), Some((&2, &mut 3)));
assert_eq!(iterator.next(), None);

Trait Implementations

impl<T, U> IntoIterator for RedBlackMap<T, U>
[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

impl<'a, T, U> IntoIterator for &'a RedBlackMap<T, U> where
    T: 'a,
    U: 'a, 
[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

impl<'a, T, U> IntoIterator for &'a mut RedBlackMap<T, U> where
    T: 'a,
    U: 'a, 
[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

impl<T, U> Default for RedBlackMap<T, U>
[src]

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

impl<'a, T, U, V: ?Sized> Index<&'a V> for RedBlackMap<T, U> where
    T: Borrow<V>,
    V: Ord
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

impl<'a, T, U, V: ?Sized> IndexMut<&'a V> for RedBlackMap<T, U> where
    T: Borrow<V>,
    V: Ord
[src]

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

Auto Trait Implementations

impl<T, U> Send for RedBlackMap<T, U> where
    T: Send,
    U: Send

impl<T, U> Sync for RedBlackMap<T, U> where
    T: Sync,
    U: Sync