Implementation of missing colections for Golang using Generics.
Free of dependencies.
Curently in early development phase.
Go 1.18+
$ go get -u github.com/ferreiravinicius/gollections
Set is a collection that contains no duplicate elements.
All implementations follows the set.Set interface.
Implemention of set backed by a hash table (Go builtin Map).
Order of insertion is not guaranteed.
This implementation is not synchronized.
Importing
import "github.com/ferreiravinicius/goset/hashset"
Create a new empty set
set := hashset.New[int]()
Create a new set initialized
set := hashset.From(1, 2, 3)
items := []int{4, 5, 6}
set := hashset.From(items...)
Create a new set with initial capacity
set := hashset.WithCapacity[int](100)
Iterating over the set using builtin loop
set := hashset.From(1, 2, 3)
for item := range set {
// foo(item)
}
Iterating over the set using ForEach
set := hashset.From(1, 2, 3)
set.ForEach(func(item int) {
// foo(item)
})