https://github.com/oniani/set
A generic set implementation for the Go programming language
https://github.com/oniani/set
Last synced: 11 months ago
JSON representation
A generic set implementation for the Go programming language
- Host: GitHub
- URL: https://github.com/oniani/set
- Owner: oniani
- License: mit
- Created: 2022-12-26T06:08:23.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-28T08:26:22.000Z (over 3 years ago)
- Last Synced: 2025-08-12T10:54:20.279Z (12 months ago)
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# set
A generic set implementation for the Go programming language.
The implementation makes use of the built-in `map` data structure.
**TODO**:
- Add tests
- Add docs
## API
```go
import "github.com/oniani/set"
func main() {
// Two ways to create and populate a set
s := Set.New("Apple", "Banana", "Cherry")
t := Set.New[string]()
t.Add("Raspberry")
t.Add("Strawberry")
t.Add("Apple")
// Check the results
fmt.Println(s, s.Len())
fmt.Println(t, t.Len())
// Union, intersection, and difference
m := s.Union(t)
n := s.Intersection(t)
o := s.Difference(t)
// Check the Results
fmt.Println(m, m.Len())
fmt.Println(n, n.Len())
fmt.Println(o, o.Len())
sHasApple, sHasCar = s.Contains("Apple"), s.Contains("Car")
sHasAll1, sHasAll2 = s.All("Car", "Laptop", "Popcorn"), s.All("Car", "Laptop", "Apple")
sHasAny1, sHasAny2 = m.Any("Car", "Laptop", "Popcorn"), m.Any("Car", "Laptop", "Apple")
// Check the results
fmt.Println(sHasApple, sHasCar)
fmt.Println(sHasAll1, sHasAll2)
fmt.Println(s_has_any1, sHasAny2)
// Clone, remove, and clear
p := s.Clone()
p.Remove("Apple")
s.Clear()
// Check the results
fmt.Println(s, s.Len())
fmt.Println(p, p.Len())
}
```
## Testing
- Unit Tests: Done (partially)
```console
$ go test -v
```
- Fuzz Tests: Done (partially)
```console
$ go test -v -fuzz FuzzAddRemoveString -fuzztime 16s
```
## License
[MIT License][license]
[godoc]: https://pkg.go.dev/golang.org/x/tools/cmd/godoc
[license]: LICENSE