[][src]Struct isomorphism::BiMap

pub struct BiMap<L, R, LH = RandomState, RH = RandomState, B = DefaultBitField> { /* fields omitted */ }

The two way hashmap itself. See the crate level documentation for more information. Uses hopscotch hashing internally.

L and R are the left and right types being mapped to eachother. LH and RH are the hash builders used to hash the left keys and right keys. B is the bitfield used to store neighbourhoods.

Methods

impl<L, R> BiMap<L, R>[src]

pub fn new() -> Self[src]

Creates a new empty BiMap.

let map: BiMap<u64, char> = BiMap::new();

impl<L, R, LH, RH, B> BiMap<L, R, LH, RH, B>[src]

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

Returns a lower bound on the number of elements that this hashmap can hold without needing to be resized.

let map: BiMap<String, String> = BiMap::new();
let capacity = map.capacity();
assert!(capacity >= 0);

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

Returns the number of pairs inside this hashmap. Each remove will decrement this count. Each insert will increment this count, but may then also decrement it by one or two if the keys being inserted already existed and were associated with other pairs.

let mut map = BiMap::new();
assert_eq!(0, map.len());

map.insert("Hello", "World");
map.insert("Hashmaps", "Are cool");
assert_eq!(2, map.len());

// this removes the ("Hello", "World") pair and the ("Hashmaps", "Are cool") pair, leaving
// only the ("Hello", "Are cool") pair behind.
map.insert("Hello", "Are cool");
assert_eq!(1, map.len());

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

Returns true if the bimap contains no pairs.

let mut map = BiMap::new();
assert!(map.is_empty());

map.insert("Hello", "World");
assert!(!map.is_empty());

Important traits for Iter<'a, L, R, B>
pub fn iter(&self) -> Iter<L, R, B>[src]

An iterator visiting all key-value pairs in an arbitrary order. The iterator element is type (&'a L, &'a R).

let mut map = BiMap::new();
map.insert("Hello", "World");
map.insert("Hashmaps", "Are cool");

for (&left, &right) in map.iter() {
    println!("{} {}", left, right);
}

impl<L, R, LH, RH, B> BiMap<L, R, LH, RH, B> where
    L: Hash + Eq,
    R: Hash + Eq,
    LH: BuildHasher,
    RH: BuildHasher,
    B: BitField
[src]

pub fn insert(&mut self, left: L, right: R) -> (Option<R>, Option<L>)[src]

Inserts an (L, R) pair into the hashmap. Returned is a (R, L) tuple of options. The Option<R> is the value that was previously associated with the inserted L (or lack thereof), and vice versa for the Option<L>.

let mut map = BiMap::new();

// neither "Hello" nor 5 were previously mapped to anything, so nothing is returned.
assert_eq!((None, None), map.insert("Hello", 5));

// "Hello" was previously mapped to 5, so remapping it to 7 means that the 5 got evicted
// from the hashmap and is therefore returned. 7 was not previously mapped to anything,
// though.
assert_eq!((Some(5), None), map.insert("Hello", 7));

// Note now that inserting "Hello" with a new right value means that 5 no longer exists in
// the hashmap.
assert_eq!(None, map.get_right(&5));

pub fn get_left<'a, Q: ?Sized>(&'a self, left: &Q) -> Option<&'a R> where
    L: Borrow<Q>,
    Q: Hash + Eq
[src]

Gets a key from the left of the hashmap. Returns the value from the right of the hashmap that associates with this key, if it exists.

let mut map = BiMap::new();
assert_eq!(None, map.get_left("Hello"));

map.insert("Hello", 5);
assert_eq!(Some(&5), map.get_left("Hello"));

pub fn get_right<'a, Q: ?Sized>(&'a self, right: &Q) -> Option<&'a L> where
    R: Borrow<Q>,
    Q: Hash + Eq
[src]

Gets a key from the right of the hashmap. Returns the value from the left of the hashmap that associates with this key, if it exists.

let mut map = BiMap::new();
assert_eq!(None, map.get_right(&5));

map.insert("Hello", 5);
assert_eq!(Some(&"Hello"), map.get_right(&5));

pub fn remove_left<Q: ?Sized>(&mut self, left: &Q) -> Option<R> where
    L: Borrow<Q>,
    Q: Hash + Eq
[src]

Removes a key from the left of the hashmap. Returns the value from the right of the hashmap that was associated with this key, if it existed. Will remove both the left and right sides of the pair, if it exists, meaning that get_right will no longer work for the value associated with the key that is removed.

let mut map = BiMap::new();
map.insert("Hello", 5);

assert_eq!(Some(&5), map.get_left("Hello"));
assert_eq!(Some(&"Hello"), map.get_right(&5));

let old = map.remove_left("Hello");
assert_eq!(Some(5), old);

assert_eq!(None, map.get_left("Hello"));
assert_eq!(None, map.get_right(&5));

pub fn remove_right<Q: ?Sized>(&mut self, right: &Q) -> Option<L> where
    R: Borrow<Q>,
    Q: Hash + Eq
[src]

Removes a key from the right of the hashmap. Returns the value from the left of the hashmap that was associated with this key, if it existed. Will remove both the left and right sides of the pair, if it exists, meaning that get_left will no longer work for the value associated with the key that is removed.

let mut map = BiMap::new();
map.insert("Hello", 5);

assert_eq!(Some(&5), map.get_left("Hello"));
assert_eq!(Some(&"Hello"), map.get_right(&5));

let old = map.remove_right(&5);
assert_eq!(Some("Hello"), old);

assert_eq!(None, map.get_left("Hello"));
assert_eq!(None, map.get_right(&5));

Trait Implementations

impl<L, R, LH, RH, B> PartialEq<BiMap<L, R, LH, RH, B>> for BiMap<L, R, LH, RH, B> where
    L: Hash + Eq,
    R: Hash + Eq,
    LH: BuildHasher,
    RH: BuildHasher,
    B: BitField
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl<L, R, LH, RH, B> Eq for BiMap<L, R, LH, RH, B> where
    L: Hash + Eq,
    R: Hash + Eq,
    LH: BuildHasher,
    RH: BuildHasher,
    B: BitField
[src]

impl<'a, L, R, LH, RH, B> IntoIterator for &'a BiMap<L, R, LH, RH, B>[src]

type Item = (&'a L, &'a R)

The type of the elements being iterated over.

type IntoIter = Iter<'a, L, R, B>

Which kind of iterator are we turning this into?

impl<L, R, LH, RH, B> IntoIterator for BiMap<L, R, LH, RH, B>[src]

type Item = (L, R)

The type of the elements being iterated over.

type IntoIter = IntoIter<L, R, B>

Which kind of iterator are we turning this into?

impl<L, R> Default for BiMap<L, R>[src]

impl<L, R, LH, RH, B> Extend<(L, R)> for BiMap<L, R, LH, RH, B> where
    L: Hash + Eq,
    R: Hash + Eq,
    LH: BuildHasher,
    RH: BuildHasher,
    B: BitField
[src]

impl<L, R, LH, RH, B> Debug for BiMap<L, R, LH, RH, B> where
    L: Debug,
    R: Debug
[src]

impl<L, R, LH, RH, B> FromIterator<(L, R)> for BiMap<L, R, LH, RH, B> where
    L: Hash + Eq,
    R: Hash + Eq,
    LH: BuildHasher + Default,
    RH: BuildHasher + Default,
    B: BitField
[src]

Auto Trait Implementations

impl<L, R, LH, RH, B> Send for BiMap<L, R, LH, RH, B> where
    B: Send,
    L: Send,
    LH: Send,
    R: Send,
    RH: Send

impl<L, R, LH, RH, B> Sync for BiMap<L, R, LH, RH, B> where
    B: Sync,
    L: Sync,
    LH: Sync,
    R: Sync,
    RH: Sync

Blanket Implementations

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.