https://github.com/davidk/memberset
A simple in-memory set implementation for storing and testing memberships in Go
https://github.com/davidk/memberset
Last synced: 25 days ago
JSON representation
A simple in-memory set implementation for storing and testing memberships in Go
- Host: GitHub
- URL: https://github.com/davidk/memberset
- Owner: davidk
- License: unlicense
- Created: 2016-07-23T02:24:28.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-01-21T23:13:03.000Z (over 7 years ago)
- Last Synced: 2025-03-21T21:45:24.363Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# memberset
[](https://goreportcard.com/report/github.com/davidk/memberset)
[](https://travis-ci.org/davidk/memberset)
[](https://godoc.org/github.com/davidk/memberset)
A simple, in-memory set used for storing and testing memberships in Go.
# Usage
Sample program:
```go
package main
import (
"fmt"
set "github.com/davidk/memberset"
)
func main() {
m := set.New()
m.Set(123)
if ok := m.Get(123); ok {
fmt.Println("Yes, 123 is a part of the set")
} else {
fmt.Println("Nope, didn't find 123 in the set")
}
// m.Add == m.Set -- this is mostly for mnemonic memory
m.Add("1234")
if ok := m.Get("1234"); ok {
fmt.Println("Yes, string 1234 has been added to the set")
}
m.Delete("1234")
if ok := m.Get("1234"); ok {
fmt.Println("Nope, string 1234 is still set. This is a bug.")
} else {
fmt.Println("Looks like string 1234 was successfully deleted!")
}
}
```
Expected output:
```bash
$ go build mtest.go
$ ./mtest
Yes, 123 is a part of the set
Yes, string 1234 has been added to the set
Looks like string 1234 was successfully deleted!
```
# Installation
### Get started by vendoring or by using `go get -u github.com/davidk/memberset`
# Related
There are other projects that have more through set implementations. Check these out:
* [deckarep/golang-set](https://github.com/deckarep/golang-set)
* [faith/set](https://github.com/fatih/set)
And [a proposal](https://github.com/golang/go/issues/16466) on golang/go to add a built-in set type. There's a link to a [playground entry](https://play.golang.org/p/VhCbdtJzwz) with a complete set implementation.
# License
[CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/)