Created
December 26, 2013 10:43
-
-
Save tsileo/8132150 to your computer and use it in GitHub Desktop.
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
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