https://github.com/ferreiravinicius/gollections
Collections for Golang using generics. Currently containing Hash Set.
https://github.com/ferreiravinicius/gollections
collections go golang hashset set
Last synced: 5 months ago
JSON representation
Collections for Golang using generics. Currently containing Hash Set.
- Host: GitHub
- URL: https://github.com/ferreiravinicius/gollections
- Owner: ferreiravinicius
- Created: 2021-12-28T00:27:14.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-30T17:35:07.000Z (over 4 years ago)
- Last Synced: 2024-06-19T17:56:33.544Z (about 2 years ago)
- Topics: collections, go, golang, hashset, set
- Language: Go
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Implementation of missing colections for Golang using Generics.
Free of dependencies.
Curently in early development phase.
## Requirements
Go **1.18+**
## Install
```console
$ go get -u github.com/ferreiravinicius/gollections
```
## Set
Set is a collection that contains no duplicate elements.
All implementations follows the set.Set interface.
## Hash Set
Implemention of set backed by a hash table (Go builtin Map).
Order of insertion is not guaranteed.
This implementation is not synchronized.
#### **API**
Importing
```golang
import "github.com/ferreiravinicius/goset/hashset"
```
Create a new empty set
```golang
set := hashset.New[int]()
```
Create a new set initialized
```golang
set := hashset.From(1, 2, 3)
items := []int{4, 5, 6}
set := hashset.From(items...)
```
Create a new set with initial capacity
```golang
set := hashset.WithCapacity[int](100)
```
Iterating over the set using builtin loop
```golang
set := hashset.From(1, 2, 3)
for item := range set {
// foo(item)
}
```
Iterating over the set using `ForEach`
```golang
set := hashset.From(1, 2, 3)
set.ForEach(func(item int) {
// foo(item)
})
```