1sets
2----
3set datastructure for go with generics and iterators. the
4api 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
32testing
33-------
34includes property-based tests using the wonderful
35testing/quick module!
36
37 go test -v