Struct eytzinger_map::EytzingerMap[][src]

pub struct EytzingerMap<S>(_);
Expand description

A map based on a generic slice-compatible type with Eytzinger binary search.

Examples

use eytzinger_map::EytzingerMap;

// `EytzingerMap` doesn't have insert. Build one from another map.
let mut movie_reviews = std::collections::BTreeMap::new();

// review some movies.
movie_reviews.insert("Office Space",       "Deals with real issues in the workplace.");
movie_reviews.insert("Pulp Fiction",       "Masterpiece.");
movie_reviews.insert("The Godfather",      "Very enjoyable.");

let movie_reviews: EytzingerMap<_> = movie_reviews.into_iter().collect();

// check for a specific one.
if !movie_reviews.contains_key("Les Misérables") {
    println!("We've got {} reviews, but Les Misérables ain't one.",
             movie_reviews.len());
}

// look up the values associated with some keys.
let to_find = ["Up!", "Office Space"];
for movie in &to_find {
    match movie_reviews.get(movie) {
       Some(review) => println!("{}: {}", movie, review),
       None => println!("{} is unreviewed.", movie)
    }
}

// Look up the value for a key (will panic if the key is not found).
println!("Movie review: {}", movie_reviews["Office Space"]);

// iterate over everything.
for (movie, review) in movie_reviews.iter() {
    println!("{}: \"{}\"", movie, review);
}

Implementations

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Examples

Basic usage:

use eytzinger_map::EytzingerMap;

let map = EytzingerMap::new(vec![(1, "a")]);
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);

Returns the key-value pair corresponding to the supplied key.

The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Examples

use eytzinger_map::EytzingerMap;

let map = EytzingerMap::new(vec![(1, "a")]);
assert_eq!(map.get_key_value(&1), Some(&(1, "a")));
assert_eq!(map.get_key_value(&2), None);

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Examples

Basic usage:

use eytzinger_map::EytzingerMap;

let map = EytzingerMap::new(vec![(1, "a")]);
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);

Gets an iterator over the entries of the map.

Examples

Basic usage:

use eytzinger_map::EytzingerMap;

let map = EytzingerMap::new(vec![(3, "c"), (2, "b"), (1, "a")]);

for (key, val) in map.iter() {
    println!("key: {} val: {}", key, val);
}

Gets an iterator over the keys of the map.

Examples

Basic usage:

use eytzinger_map::EytzingerMap;

let map = EytzingerMap::new(vec![(2, "b"), (1, "a")]);

for key in map.keys() {
    println!("{}", key);
}

Gets an iterator over the values of the map.

Examples

Basic usage:

use eytzinger_map::EytzingerMap;

let map = EytzingerMap::new(vec![(1, "hello"), (2, "goodbye")]);

for val in map.values() {
    println!("{}", val);
}

Returns the number of elements in the map.

Examples

Basic usage:

use eytzinger_map::EytzingerMap;

let mut a = EytzingerMap::new(vec![]);
assert_eq!(a.len(), 0);
a = EytzingerMap::new(vec![(1, "a")]);
assert_eq!(a.len(), 1);

Returns true if the map contains no elements.

Examples

Basic usage:

use eytzinger_map::EytzingerMap;

let mut a = EytzingerMap::new(vec![]);
assert!(a.is_empty());
a = EytzingerMap::new(vec![(1, "a")]);
assert!(!a.is_empty());

Returns a mutable reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Examples

Basic usage:

use eytzinger_map::EytzingerMap;

let mut map = EytzingerMap::new(vec![(1, "a")]);
if let Some(x) = map.get_mut(&1) {
    *x = "b";
}
assert_eq!(map[&1], "b");

Gets a mutable iterator over the entries of the map.

Examples

Basic usage:

use eytzinger_map::EytzingerMap;

let mut map = EytzingerMap::new(vec![("a", 1), ("b", 2), ("c", 3)]);

// Update all values
for (_, val) in map.iter_mut() {
    *val *= 2;
}

for (key, val) in map.iter() {
    println!("key: {} val: {}", key, val);
}

Gets a mutable iterator over the values of the map.

Examples

Basic usage:

use eytzinger_map::EytzingerMap;

let mut map = EytzingerMap::new(vec![("a", 1), ("b", 2), ("c", 3)]);

for val in map.values_mut() {
    *val = *val + 10;
}

for val in map.values() {
    println!("{}", val);
}

Trait Implementations

Performs the conversion.

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Creates a value from an iterator. Read more

Feeds this value into the given Hasher. Read more

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

Returns a reference to the value corresponding to the supplied key.

Panics

Panics if the key is not present in the BTreeMap.

The returned type after indexing.

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

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

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.