4 releases

0.1.3 Mar 13, 2019
0.1.2 Apr 23, 2018
0.1.1 Apr 23, 2018
0.1.0 Apr 23, 2018

#2104 in Data structures

24 downloads per month

MIT license

43KB
827 lines

isomorphism

2 directional hashmaps in rust

Build Status Crates.io

This crate aims to provide a data structure that can store a 1:1 relation between two different types. This data structure also provides constant time lookup within this relation - in either direction.

use isomorphism::BiMap;

fn main() {
    let mut map = BiMap::new();
    map.insert("Hello", "World");

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

lib.rs:

Bidirectional hashmaps! This crate aims to provide a data structure that can take store a 1:1 relation between two different types, and provide constant time lookup within this relation.

Unlike a regular hashmap, which provides lookups from "keys" to "values", the two directional hashmap provides lookups from "left keys" to "right keys" and from "right keys" to "left keys". The difference between a "value" in a hashmap and a "right key" in a BiMap is that the right key must be hashable and comparable, and that duplicate right keys cannot exist within the bimap, even if they have different left keys mapping to them.

Dependencies

~175KB