-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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.
There are no files selected for viewing
This file contains 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
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 | ||
} |