https://github.com/be-nice/goset
Generic set implementations in golang
https://github.com/be-nice/goset
go golang gomodule set
Last synced: 5 months ago
JSON representation
Generic set implementations in golang
- Host: GitHub
- URL: https://github.com/be-nice/goset
- Owner: be-nice
- License: mit
- Created: 2025-07-16T01:26:33.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-16T20:21:16.000Z (11 months ago)
- Last Synced: 2026-01-12T05:25:28.848Z (5 months ago)
- Topics: go, golang, gomodule, set
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goset
A simple wrapper around golangs map[T]struct{} for easier set methods
Accepts data types that satisfy the builtin comparable generic.
## how to use
```go
import "github.com/be-nice/goset"
```
**Initialize a new set**
```go
s := goset.New[type]()
```
**Build set from slice**
```go
s := goset.FromSlice(slice)
```
**Make a clone from set A**
```go
s := a.Clone()
```
**Clear set**
```go
s.Clear()
```
### set methods
**add item**
```go
func (s *Set[T]) Add(val T)
```
**Remove item**
```go
func (s *Set[T]) Del(val T)
```
**Check if item is in the set**
```go
func (s *Set[T]) Contains(val T) bool
```
**Get number of items in the set**
```go
func (s *Set[T]) Len() int
```
**Return set values in a slice**
```go
func (s *Set[T]) Values() []T
```
**Return union of A and B**
```go
func (a *Set[T]) Union(b *Set[T]) *Set[T]
```
**Return intersection of A and B**
```go
func (a *Set[T]) Inter(b *Set[T]) *Set[T]
```
**Return difference of A and B**
```go
func (a *Set[T]) Diff(b *Set[T]) *Set[T]
```
**Return symmetric difference between A and B**
```go
func (a *Set[T]) SymDiff(b *Set[T]) *Set[T]
```
**Compare if set A and B are equal**
```go
func (a *Set[T]) IsEqual(b *Set[T]) bool
```
**Check if A is subset of B**
```go
func (a *Set[T]) IsSubset(b *Set[T]) bool
```
**Check if A is proper subset of B**
```go
func (a *Set[T]) IsProperSubset(b *Set[T]) bool
```