Skip to content

Commit

Permalink
Add set util
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément Blaise committed Jan 8, 2021
1 parent d40a179 commit 010e39c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions internal/utils/set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package utils

var exists = struct{}{}

type set struct {
m map[string]struct{}
}

func NewSet() *set {
s := &set{}
s.m = make(map[string]struct{})
return s
}

func (s *set) Add(value string) {
s.m[value] = exists
}

func (s *set) Remove(value string) {
delete(s.m, value)
}

func (s *set) List() (list []string) {
for key, _ := range s.m {
list = append(list, key)
}
return
}

func (s *set) Contains(value string) bool {
_, c := s.m[value]
return c
}

0 comments on commit 010e39c

Please sign in to comment.