Skip to content

Instantly share code, notes, and snippets.

@perrie625
Created April 19, 2017 09:55
Show Gist options
  • Save perrie625/f5c33e48735fc0176cf991b44754347d to your computer and use it in GitHub Desktop.
Save perrie625/f5c33e48735fc0176cf991b44754347d to your computer and use it in GitHub Desktop.
Golang Gist
var itemExists = struct{}{}
type Set struct {
items map[interface{}]struct{}
}
func New() *Set {
return &Set{items: make(map[interface{}]struct{})}
}
func (set *Set) Add(item interface{}) {
set.items[item] = itemExists
}
func (set *Set) Remove(item interface{}) {
delete(set.items, item)
}
func (set *Set) Contains(item interface{}) bool {
if _, contains := set.items[item]; !contains {
return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment