#linked-hash-map #hash-set #ordered-hash-set

no-std ordered_hash_map

HashMap which preserves insertion order

5 releases (3 breaking)

0.4.0 Nov 12, 2023
0.3.1 Nov 10, 2023
0.3.0 Nov 10, 2023
0.2.0 Mar 4, 2023
0.1.0 Mar 1, 2023

#944 in Data structures

Download history 446/week @ 2024-07-19 519/week @ 2024-07-26 390/week @ 2024-08-02 565/week @ 2024-08-09 659/week @ 2024-08-16 452/week @ 2024-08-23 716/week @ 2024-08-30 649/week @ 2024-09-06 296/week @ 2024-09-13 569/week @ 2024-09-20 272/week @ 2024-09-27 562/week @ 2024-10-04 1753/week @ 2024-10-11 4686/week @ 2024-10-18 5709/week @ 2024-10-25 6760/week @ 2024-11-01

19,035 downloads per month
Used in 10 crates (7 directly)

BSD-2-Clause

94KB
2K SLoC

OrderedHashMap

A HashMap (and Set) which preserves insertion order.

This crate provides a no_std implementation of a Ordered Hash Map (and it's corresponding Set) using as little unsafe as possible. MIRI is used to audit the unsafe which does exist.

The API aims to match the standard library HashMap/Set with additional LinkedList style methods and ordered-itertors.

Changelog

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.

Features

serde - Enable serde Serialization and Deserialization

Usage

use ordered_hash_map::OrderedHashMap;

let mut map: OrderedHashMap<_, _> = [(1, "one"), (2, "two")].into_iter().collect();
map.insert(3, "three");
assert_eq!(map.iter().next(), Some((&1, &"one")));

Dependencies

~2MB
~25K SLoC