是否存在保留插入顺序(认为Vec)但仅跟踪唯一值(认为HashSet)的类型?我想避免使用,Vec因为在插入之前我首先需要检查该值是否存在。
linked_hash_set板条箱现在可用。它基于尽可能接近linked-hash-mapstd HashSetAPI 的
板条箱。
extern crate linked_hash_set;
use linked_hash_set::LinkedHashSet;
let mut set = LinkedHashSet::new();
set.insert(234);
set.insert(123);
set.insert(345);
set.insert(123);
assert_eq!(set.into_iter().collect::<Vec<_>>(), vec![234, 345, 123]);
Run Code Online (Sandbox Code Playgroud)
小智 5
linked-hash-map由于处于维护模式,因此正在更新答案(请参阅github commit)
2021 年 9 月最受欢迎的 github crate:
IndexSet.