7 releases

Uses new Rust 2024

0.1.6 Nov 9, 2025
0.1.5 Dec 22, 2024
0.1.4 Jul 21, 2020
0.1.3 Jun 7, 2018
0.1.0 Oct 25, 2017

#48 in Data structures

Download history 299866/week @ 2026-01-22 299842/week @ 2026-01-29 283780/week @ 2026-02-05 258396/week @ 2026-02-12 325874/week @ 2026-02-19 336323/week @ 2026-02-26 443717/week @ 2026-03-05 368027/week @ 2026-03-12 344804/week @ 2026-03-19 339533/week @ 2026-03-26 331324/week @ 2026-04-02 357491/week @ 2026-04-09 360367/week @ 2026-04-16 369555/week @ 2026-04-23 306710/week @ 2026-04-30 411763/week @ 2026-05-07

1,519,984 downloads per month
Used in 655 crates (47 directly)

Apache-2.0

59KB
997 lines

linked_hash_set crates.io Documentation

This library provides an hashed set with predictable iteration order, based on the insertion order of elements. It is implemented as a linked_hash_map::LinkedHashMap where the value is (), in a similar way as HashSet is implemented from HashMap in stdlib.

Comparison with std HashSet

General usage is very similar to a traditional hashed set, but this structure also maintains insertion order.

Compared to HashSet, a LinkedHashSet uses an additional doubly-linked list running through its entries. As such methods front(), pop_front(), back(), pop_back() and refresh() are provided.

Comparison with IndexSet

Compared to indexmap::IndexSet, while both maintain insertion order a LinkedHashSet uses a linked list allowing performant removals that don't affect the order of the remaining elements. However, when this distinction is unimportant indexmap should be the faster option.

Example

let mut set = linked_hash_set::LinkedHashSet::new();
assert!(set.insert(234));
assert!(set.insert(123));
assert!(set.insert(345));
assert!(!set.insert(123)); // Also see `insert_if_absent` which won't change order

assert_eq!(set.into_iter().collect::<Vec<_>>(), vec![234, 345, 123]);

Minimum supported rust compiler

This crate is maintained with latest stable rust.

Dependencies

~155KB