6 releases (breaking)

0.5.0 Sep 12, 2025
0.4.0 Nov 12, 2023
0.3.1 Nov 10, 2023
0.2.0 Mar 4, 2023
0.1.0 Mar 1, 2023

#239 in Data structures

Download history 98777/week @ 2025-10-12 122667/week @ 2025-10-19 135553/week @ 2025-10-26 136565/week @ 2025-11-02 133056/week @ 2025-11-09 137287/week @ 2025-11-16 68140/week @ 2025-11-23 40322/week @ 2025-11-30 31794/week @ 2025-12-07 31708/week @ 2025-12-14 17091/week @ 2025-12-21 14760/week @ 2025-12-28 31622/week @ 2026-01-04 31516/week @ 2026-01-11 19397/week @ 2026-01-18 29750/week @ 2026-01-25

113,996 downloads per month
Used in 19 crates (8 directly)

BSD-2-Clause

94KB
2K SLoC

OrderedHashMap

An ordered hash map implementation for Rust

This crate provides a data structure that combines the features of a hash map and a linked list. It maintains the order of insertion while allowing fast key lookups. Features:

  • Fast Lookup: HashMap insertions and fetches are as quick as HashMap
  • Ordered Iteration: Iterators walk in insertion order
  • Serde Support: Serialize/Deserialize a map while preserving order

The aim is to match the standard library HashMap/Set with additional LinkedList style methods and ordered-iterators.

Changelog

Features

serde - Enable serde Serialization and Deserialization

Usage

use ordered_hash_map::OrderedHashMap;

fn main() {
    let mut map = OrderedHashMap::new();

    map.insert("apple", 5);
    map.insert("banana", 3);
    map.insert("cherry", 8);

    // Map access
    println!("banana: {}", map.get("banana").unwrap());

    // Insertion-order iteration
    for (k, v) in map.iter() {
        println!("{}: {}", k, v);
    }
}

Details

This crate is powered by hashbrown, leveraging the already well vetted HashMap implementation and added the bits required to implement a LinkedList within the map. The additional memory footprint of the OrderedHashMap over the hashbrown HashMap is 2 pointers upon making a collection + 3 pointers per element. The pointers arise from the LinkedList where the collection itself has a pointer to the head and the tail, each node has a pointer to the next and previous node, and the Key in the map is a pointer into the Value where it lives.

Dependencies

~1MB
~17K SLoC