mirror of
https://github.com/lyx0/yaf.git
synced 2024-11-13 19:49:53 +01:00
34 lines
526 B
Go
34 lines
526 B
Go
package main
|
|
|
|
type Set struct {
|
|
_map map[interface{}]struct{}
|
|
}
|
|
|
|
func NewSet() *Set {
|
|
set := &Set{}
|
|
set._map = make(map[interface{}]struct{})
|
|
return set
|
|
}
|
|
|
|
func (set *Set) Contains(value interface{}) bool {
|
|
_, ok := set._map[value]
|
|
return ok
|
|
}
|
|
|
|
func (set *Set) Insert(value interface{}) bool {
|
|
if set.Contains(value) {
|
|
return false
|
|
}
|
|
|
|
set._map[value] = struct{}{}
|
|
return true
|
|
}
|
|
|
|
func (set *Set) Remove(value interface{}) bool {
|
|
if !set.Contains(value) {
|
|
return false
|
|
}
|
|
|
|
delete(set._map, value)
|
|
return true
|
|
}
|