https://github.com/alexheretic/linked-hash-set
Rust HashSet with insertion ordering
https://github.com/alexheretic/linked-hash-set
Last synced: 3 months ago
JSON representation
Rust HashSet with insertion ordering
- Host: GitHub
- URL: https://github.com/alexheretic/linked-hash-set
- Owner: alexheretic
- License: apache-2.0
- Created: 2017-10-25T12:21:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-21T22:30:00.000Z (almost 5 years ago)
- Last Synced: 2024-01-29T13:01:12.075Z (about 1 year ago)
- Language: Rust
- Size: 33.2 KB
- Stars: 37
- Watchers: 4
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
linked\_hash\_set
[](https://crates.io/crates/linked_hash_set)
[](https://docs.rs/linked_hash_set)
=================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`](https://github.com/contain-rs/linked-hash-map) where the value is `()`, in a similar way as `HashSet` is implemented from `HashMap` in stdlib.## Comparison with std [`HashSet`](https://doc.rust-lang.org/std/collections/struct.HashSet.html)
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`](https://github.com/bluss/indexmap)
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
```rust
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 orderassert_eq!(set.into_iter().collect::>(), vec![234, 345, 123]);
```## Minimum supported rust compiler
This crate is maintained with [latest stable rust](https://gist.github.com/alexheretic/d1e98d8433b602e57f5d0a9637927e0c).