Struct isomorphism::BiMap [] [src]

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]

[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]

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

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

[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>
[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]

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

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

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

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

[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> Default for BiMap<L, R>
[src]

[src]

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

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

[src]

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

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<L, R, LH, RH, B> Debug for BiMap<L, R, LH, RH, B> where
    L: Debug,
    R: Debug
[src]

[src]

Formats the value using the given formatter. Read more

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

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]

[src]

Creates a value from an iterator. Read more

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]

[src]

Extends a collection with the contents of an iterator. Read more

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