#hash-map #key #generated #usize #value #store-key #indexed

indexed_map

HashMap wrapper where each value corresponds to a uniquely generated usize key

2 releases

0.1.1 Aug 15, 2019
0.1.0 Aug 15, 2019

#254 in Database implementations

MIT license

5KB

indexed_map

A wrapper for HashMap that maps each value to a uniquely generated usize key.

Crates.io Crates.io Build Status

Example usage:

use indexed_map::IndexedMap;

fn  main() {
    // create an empty `IndexedMap`, just like `HashMap`
    let mut fruits = IndexedMap::new();
    
    // insert some values and store their keys for later use
    let apple = fruits.insert("Apple");
    let orange = fruits.insert("Orange");
    let pear = fruits.insert("Pear");
    
    // list the values we've inserted
    for fruit in fruits.inner().values() {
        println!("{}", fruit);
    }
    
    // remove the values using the unique keys returned from `IndexedMap::insert`
    fruits.inner_mut().remove(&apple);
    fruits.inner_mut().remove(&orange);
    fruits.inner_mut().remove(&pear);
    
    // the map is now empty
    println!("{:?}", fruits);
}

No runtime deps