1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use std::borrow::Borrow;
use std::collections::HashSet;
use std::hash::Hash;
use std::ops::Sub;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct UnorderedHashSet<Key: Hash + Eq>(HashSet<Key>);
impl<Key: Hash + Eq> UnorderedHashSet<Key> {
pub fn insert(&mut self, key: Key) -> bool {
self.0.insert(key)
}
pub fn extend<I: IntoIterator<Item = Key>>(&mut self, iter: I) {
self.0.extend(iter)
}
pub fn extend_unordered(&mut self, other: Self) {
self.0.extend(other.0)
}
pub fn contains<Q: ?Sized + Hash + Eq>(&self, value: &Q) -> bool
where
Key: Borrow<Q>,
{
self.0.contains(value)
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn clear(&mut self) {
self.0.clear()
}
}
impl<Key: Hash + Eq> Default for UnorderedHashSet<Key> {
fn default() -> Self {
Self(Default::default())
}
}
impl<Key: Hash + Eq> FromIterator<Key> for UnorderedHashSet<Key> {
fn from_iter<T: IntoIterator<Item = Key>>(iter: T) -> Self {
Self(iter.into_iter().collect())
}
}
impl<'a, Key: Hash + Eq + Clone> Sub<&'a UnorderedHashSet<Key>> for &'a UnorderedHashSet<Key> {
type Output = UnorderedHashSet<Key>;
fn sub(self, rhs: Self) -> Self::Output {
UnorderedHashSet::<Key>(&self.0 - &rhs.0)
}
}