Crates.io | linked_hash_set |
lib.rs | linked_hash_set |
version | |
source | src |
created_at | 2017-10-25 13:44:18.61537+00 |
updated_at | 2024-12-22 08:10:02.415783+00 |
description | HashSet with insertion ordering |
homepage | |
repository | https://github.com/alexheretic/linked-hash-set |
max_upload_size | |
id | 36860 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.
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.
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.
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]);
This crate is maintained with latest stable rust.