Created
April 19, 2017 09:55
-
-
Save perrie625/f5c33e48735fc0176cf991b44754347d to your computer and use it in GitHub Desktop.
Golang Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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