Struct eytzinger_map::EytzingerMap[][src]

pub struct EytzingerMap<S>(_);

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

impl<S> EytzingerMap<S> where
    S: AsSlice
[src]

pub fn new(s: S) -> Self where
    S: AsMutSlice
[src]

pub fn from_sorted(s: S) -> Self where
    S: AsSlice
[src]

pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&S::Value> where
    S::Key: Borrow<Q> + Ord,
    Q: Ord
[src]

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

pub fn get_key_value<Q: ?Sized>(&self, key: &Q) -> Option<&(S::Key, S::Value)> where
    S::Key: Borrow<Q> + Ord,
    Q: Ord
[src]

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

pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
    S::Key: Borrow<Q> + Ord,
    Q: Ord
[src]

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

pub fn iter(&self) -> impl Iterator<Item = &(S::Key, S::Value)>[src]

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

pub fn keys(&self) -> impl Iterator<Item = &S::Key>[src]

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

pub fn values(&self) -> impl Iterator<Item = &S::Value>[src]

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

pub fn len(&self) -> usize[src]

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

pub fn is_empty(&self) -> bool[src]

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

impl<S> EytzingerMap<S> where
    S: AsMutSlice
[src]

pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut S::Value> where
    S::Key: Borrow<Q> + Ord,
    Q: Ord
[src]

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

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut (S::Key, S::Value)>[src]

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

pub fn values_mut(&mut self) -> impl Iterator<Item = &mut S::Value>[src]

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

impl<'a, K, V> EytzingerMap<&'a [(K, V)]>[src]

pub fn from_sorted_ref(s: &'a [(K, V)]) -> Self[src]

pub fn from_ref(s: &'a mut [(K, V)]) -> Self[src]

Trait Implementations

impl<S, K, V> AsMut<[(K, V)]> for EytzingerMap<S> where
    K: Ord,
    S: AsMut<[(K, V)]>, 
[src]

fn as_mut(&mut self) -> &mut [(K, V)][src]

Performs the conversion.

impl<S, K, V> AsRef<[(K, V)]> for EytzingerMap<S> where
    S: AsRef<[(K, V)]>, 
[src]

fn as_ref(&self) -> &[(K, V)][src]

Performs the conversion.

impl<S: Clone> Clone for EytzingerMap<S>[src]

fn clone(&self) -> EytzingerMap<S>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<S: Debug> Debug for EytzingerMap<S>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<S: Default> Default for EytzingerMap<S>[src]

fn default() -> EytzingerMap<S>[src]

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

impl<K, V> FromIterator<(K, V)> for EytzingerMap<Vec<(K, V)>> where
    K: Ord
[src]

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self[src]

Creates a value from an iterator. Read more

impl<S: Hash> Hash for EytzingerMap<S>[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

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

impl<Q: ?Sized, S> Index<&'_ Q> for EytzingerMap<S> where
    S::Key: Borrow<Q> + Ord,
    Q: Ord,
    S: AsSlice
[src]

fn index(&self, key: &Q) -> &S::Value[src]

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

Panics

Panics if the key is not present in the BTreeMap.

type Output = S::Value

The returned type after indexing.

impl<S, K, V> IntoIterator for EytzingerMap<S> where
    S: IntoIterator<Item = (K, V)>, 
[src]

type Item = (K, V)

The type of the elements being iterated over.

type IntoIter = S::IntoIter

Which kind of iterator are we turning this into?

fn into_iter(self) -> S::IntoIter[src]

Creates an iterator from a value. Read more

impl<S: PartialEq> PartialEq<EytzingerMap<S>> for EytzingerMap<S>[src]

fn eq(&self, other: &EytzingerMap<S>) -> bool[src]

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

fn ne(&self, other: &EytzingerMap<S>) -> bool[src]

This method tests for !=.

impl<S: Copy> Copy for EytzingerMap<S>[src]

impl<S: Eq> Eq for EytzingerMap<S>[src]

impl<S> StructuralEq for EytzingerMap<S>[src]

impl<S> StructuralPartialEq for EytzingerMap<S>[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.