[feat] first version
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package set
|
||||
|
||||
type Set map[interface{}]struct{}
|
||||
|
||||
func NewSet() Set {
|
||||
return make(map[interface{}]struct{})
|
||||
}
|
||||
|
||||
func (s Set) Add(i interface{}) {
|
||||
s[i] = struct{}{}
|
||||
}
|
||||
|
||||
func (s Set) Has(i interface{}) bool {
|
||||
_, ok := s[i]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (s Set) Size() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func (s Set) Keys() []interface{} {
|
||||
keys := make([]interface{}, 0)
|
||||
|
||||
for k, _ := range s {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
||||
Reference in New Issue
Block a user