4 releases

✓ Uses Rust 2018 edition

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

#216 in Data structures

Download history 106/week @ 2019-07-20 80/week @ 2019-07-27 18/week @ 2019-08-03 15/week @ 2019-08-10 19/week @ 2019-08-17 59/week @ 2019-08-24 13/week @ 2019-08-31 14/week @ 2019-09-07 21/week @ 2019-09-14 26/week @ 2019-09-21 5/week @ 2019-09-28 4/week @ 2019-10-05 1/week @ 2019-10-12 9/week @ 2019-10-19 23/week @ 2019-10-26

259 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