https://github.com/r167/go-sets
A minimal set library for golang
https://github.com/r167/go-sets
Last synced: 5 months ago
JSON representation
A minimal set library for golang
- Host: GitHub
- URL: https://github.com/r167/go-sets
- Owner: R167
- License: mit
- Created: 2023-11-18T10:46:48.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-20T19:01:33.000Z (over 2 years ago)
- Last Synced: 2025-07-10T10:46:48.998Z (about 1 year ago)
- Language: Go
- Size: 10.7 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Sets!
A minimal set library for golang. This tinylib eschews any dependencies and implements common, optimized set operations on `type Set[E comparable] map[E]struct{}`
[](https://pkg.go.dev/github.com/R167/go-sets) [](https://goreportcard.com/report/github.com/R167/go-sets) [](https://github.com/R167/go-sets/actions/workflows/ci.yaml)
Supported set operations:
- Union: A⋃B
- Intersection: A⋂B
- Difference: A-B
Supported checks:
- Subset: A⊆B
- Superset: A⊇B
- Equality: A=B
## Usage
```go
package main
import (
"fmt"
"github.com/R167/go-sets"
)
func main() {
a := sets.New(1, 2, 3)
b := sets.New(3, 4, 5)
fmt.Println(a.Union(b)) // {1, 2, 3, 4, 5}
fmt.Println(a.Intersect(b)) // {3}
fmt.Println(a.Difference(b)) // {1, 2}
a2 := sets.New(1, 2)
fmt.Println(a2.Subset(a)) // true
fmt.Println(a.Subset(a2)) // false
fmt.Println(a.Equal(b)) // false
}
```