1 pub use rustc_hash::FxHashSet;
2 use std::borrow::Borrow;
6 /// A deterministic wrapper around FxHashSet that does not provide iteration support.
8 /// It supports insert, remove, get functions from FxHashSet.
9 /// It also allows to convert hashset to a sorted vector with the method `into_sorted_vector()`.
11 pub struct StableSet<T> {
15 impl<T> Default for StableSet<T>
19 fn default() -> StableSet<T> {
24 impl<T> fmt::Debug for StableSet<T>
26 T: Eq + Hash + fmt::Debug,
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 write!(f, "{:?}", self.base)
33 impl<T> PartialEq<StableSet<T>> for StableSet<T>
37 fn eq(&self, other: &StableSet<T>) -> bool {
38 self.base == other.base
42 impl<T> Eq for StableSet<T> where T: Eq + Hash {}
44 impl<T: Hash + Eq> StableSet<T> {
45 pub fn new() -> StableSet<T> {
46 StableSet { base: FxHashSet::default() }
49 pub fn into_sorted_vector(self) -> Vec<T>
53 let mut vector = self.base.into_iter().collect::<Vec<_>>();
54 vector.sort_unstable();
58 pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>
66 pub fn insert(&mut self, value: T) -> bool {
67 self.base.insert(value)
70 pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool
75 self.base.remove(value)