A hash map with stable indices

3 releases

0.1.2 Jan 11, 2019
0.1.1 Nov 17, 2018
0.1.0 Nov 16, 2018

#633 in Data structures

Download history 1/week @ 2020-01-21 68/week @ 2020-01-28 8/week @ 2020-02-11 17/week @ 2020-02-18 72/week @ 2020-02-25 12/week @ 2020-03-03 7/week @ 2020-03-10 9/week @ 2020-03-17 9/week @ 2020-03-24 37/week @ 2020-03-31 10/week @ 2020-04-07 12/week @ 2020-04-14 1/week @ 2020-04-21 72/week @ 2020-04-28 1/week @ 2020-05-05

87 downloads per month

MIT license



Build Status Crates.io

A hash map whose entries can be indexed into. This is just like indexmap, but the indices are stable (i.e., indices are not perturbed upon removal of an entry). This makes it an ideal data structure for implementing graphs.

The underlying hash map implementation (linear probing) is not particularly fast or smart. I'm more interested in the stable indices property than having a super-fast hash map at the moment. However, it'd be great to switch to either Robin Hood Hashing or to the SwissTable approach. The idea of stable indices can be applied to any hash map implementation.


  • A drop-in replacement of Rust's HashMap.
  • Inserting a key-value pair gives back an index to refer back to it. Using the index bypasses the need to compute the hash of the key.
  • Removing a key-value pair frees up the index that was using it. A future insertion will reuse the index. Thus, indices are not compact after a removal.


Add this to your Cargo.toml

holyhashmap = "0.1"

and this to your crate root:

extern crate holyhashmap;

For serde support, add this instead to your Cargo.toml:

holyhashmap = { version = "0.1", features = ["serde"] }


Here's how one might implement a graph data structure utilizing indices:

extern crate holyhashmap;

use holyhashmap::{HolyHashMap, EntryIndex};

type NodeIndex = EntryIndex;

struct Neighbors {
    incoming: Vec<NodeIndex>,
    outgoing: Vec<NodeIndex>,

pub struct Graph<N, E>
    N: Eq + Hash,
    // The nodes in the graph. A mapping of the node key `N` to its neighbors.
    nodes: HolyHashMap<N, Neighbors>,

    // The edges in the graph. A mapping between node index pairs and the edge
    // weight `E`.
    edges: HolyHashMap<(NodeIndex, NodeIndex), E>,


MIT license