tangled
alpha
login
or
join now
oppi.li
/
sets
0
fork
atom
a rusty set datastructure for go
0
fork
atom
overview
issues
pulls
pipelines
readme
Signed-off-by: oppiliappan <me@oppi.li>
oppi.li
3 months ago
c6089afd
714a80a6
verified
This commit was signed with the committer's
known signature
.
oppi.li
SSH Key Fingerprint:
SHA256:yQs05DbrlPDC2pBXLxqOdLYEswq3oEBnHaJiBP7bOlM=
+41
-4
5 changed files
expand all
collapse all
unified
split
gen.go
go.mod
readme.txt
set.go
set_test.go
+1
-1
gen.go
···
1
1
-
package set
1
1
+
package sets
2
2
3
3
import (
4
4
"math/rand"
+1
-1
go.mod
···
1
1
-
module tangled.org/oppi.li/set
1
1
+
module tangled.org/oppi.li/sets
2
2
3
3
go 1.25.0
+37
readme.txt
···
1
1
+
sets
2
2
+
----
3
3
+
set datastructure for go with generics and iterators. the
4
4
+
api is supposed to mimic rust's std::collections::HashSet api.
5
5
+
6
6
+
import "tangled.org/oppi.li/sets"
7
7
+
8
8
+
s1 := sets.Collect(slices.Values([]int{1, 2, 3, 4}))
9
9
+
s2 := sets.Collect(slices.Values([]int{1, 2, 3, 4, 5, 6}))
10
10
+
11
11
+
union := sets.Collect(s1.Union(s2))
12
12
+
intersect := sets.Collect(s1.Intersection(s2))
13
13
+
diff := sets.Collect(s1.Difference(s2))
14
14
+
symdiff := sets.Collect(s1.SymmetricDifference(s2))
15
15
+
16
16
+
s1.Len() // 4
17
17
+
s1.Contains(1) // true
18
18
+
s1.IsEmpty() // false
19
19
+
s1.IsSubset(s2) // true
20
20
+
s1.IsSuperset(s2) // false
21
21
+
s1.IsDisjoint(s2) // false
22
22
+
23
23
+
if exists := s1.Insert(1); exists {
24
24
+
// already existed in set
25
25
+
}
26
26
+
27
27
+
if existed := s1.Remove(1); existed {
28
28
+
// existed in set, now removed
29
29
+
}
30
30
+
31
31
+
32
32
+
testing
33
33
+
-------
34
34
+
includes property-based tests using the wonderful
35
35
+
testing/quick module!
36
36
+
37
37
+
go test -v
+1
-1
set.go
···
1
1
-
package set
1
1
+
package sets
2
2
3
3
import (
4
4
"iter"
+1
-1
set_test.go
···
1
1
-
package set
1
1
+
package sets
2
2
3
3
import (
4
4
"slices"