a rusty set datastructure for go

readme

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li c6089afd 714a80a6

verified
+1 -1
gen.go
··· 1 - package set 1 + package sets 2 2 3 3 import ( 4 4 "math/rand"
+1 -1
go.mod
··· 1 - module tangled.org/oppi.li/set 1 + module tangled.org/oppi.li/sets 2 2 3 3 go 1.25.0
+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
+1 -1
set.go
··· 1 - package set 1 + package sets 2 2 3 3 import ( 4 4 "iter"
+1 -1
set_test.go
··· 1 - package set 1 + package sets 2 2 3 3 import ( 4 4 "slices"