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