Skip to content

Instantly share code, notes, and snippets.

@tsileo
Created December 26, 2013 10:43
Show Gist options
  • Save tsileo/8132150 to your computer and use it in GitHub Desktop.
Save tsileo/8132150 to your computer and use it in GitHub Desktop.
type Set struct {
set map[string]bool
}
func NewSet() *Set {
return &Set{make(map[string]bool)}
}
func (set *Set) Add(s string) bool {
_, found := set.set[s]
set.set[s] = true
return !found //False if it existed already
}
func (set *Set) Get(s string) bool {
_, found := set.set[s]
return found //true if it existed already
}
func (set *Set) Remove(s string) {
delete(set.set, s)
}
func (set *Set) Keys() (out []string) {
for k, _ := range set.set {
out = append(out, k)
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment