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 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
Returns the “default value” for a type. 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
impl<S> RefUnwindSafe for EytzingerMap<S> where
S: RefUnwindSafe,
impl<S> Send for EytzingerMap<S> where
S: Send,
impl<S> Sync for EytzingerMap<S> where
S: Sync,
impl<S> Unpin for EytzingerMap<S> where
S: Unpin,
impl<S> UnwindSafe for EytzingerMap<S> where
S: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more