31 lines
414 B
Go
31 lines
414 B
Go
|
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
|
||
|
}
|