+1
-1
go.mod
+1
-1
go.mod
+37
readme.txt
+37
readme.txt
···
1
+
sets
2
+
----
3
+
set datastructure for go with generics and iterators. the
4
+
api is supposed to mimic rust's std::collections::HashSet api.
5
+
6
+
import "tangled.org/oppi.li/sets"
7
+
8
+
s1 := sets.Collect(slices.Values([]int{1, 2, 3, 4}))
9
+
s2 := sets.Collect(slices.Values([]int{1, 2, 3, 4, 5, 6}))
10
+
11
+
union := sets.Collect(s1.Union(s2))
12
+
intersect := sets.Collect(s1.Intersection(s2))
13
+
diff := sets.Collect(s1.Difference(s2))
14
+
symdiff := sets.Collect(s1.SymmetricDifference(s2))
15
+
16
+
s1.Len() // 4
17
+
s1.Contains(1) // true
18
+
s1.IsEmpty() // false
19
+
s1.IsSubset(s2) // true
20
+
s1.IsSuperset(s2) // false
21
+
s1.IsDisjoint(s2) // false
22
+
23
+
if exists := s1.Insert(1); exists {
24
+
// already existed in set
25
+
}
26
+
27
+
if existed := s1.Remove(1); existed {
28
+
// existed in set, now removed
29
+
}
30
+
31
+
32
+
testing
33
+
-------
34
+
includes property-based tests using the wonderful
35
+
testing/quick module!
36
+
37
+
go test -v