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()
and pop_back()
are provided.
OrderSet
Compared to ordermap::OrderSet
, 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 ordermap should be the faster option.
```rust extern crate linkedhashset; use linkedhashset::LinkedHashSet;
let mut set = LinkedHashSet::new(); set.insert(234); set.insert(123); set.insert(345); let new_element = set.insert(123);
asserteq!(newelement, false);
asserteq!(set.intoiter().collect::