2014-09-15 02:10:50 +03:00
|
|
|
package ethutil
|
|
|
|
|
|
|
|
type Settable interface {
|
|
|
|
AsSet() UniqueSet
|
|
|
|
}
|
|
|
|
|
2014-09-15 16:42:12 +03:00
|
|
|
type Stringable interface {
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type UniqueSet map[string]struct{}
|
2014-09-15 02:10:50 +03:00
|
|
|
|
2014-09-15 16:42:12 +03:00
|
|
|
func NewSet(v ...Stringable) UniqueSet {
|
2014-09-15 02:10:50 +03:00
|
|
|
set := make(UniqueSet)
|
|
|
|
for _, val := range v {
|
|
|
|
set.Insert(val)
|
|
|
|
}
|
|
|
|
|
|
|
|
return set
|
|
|
|
}
|
|
|
|
|
2014-09-15 16:42:12 +03:00
|
|
|
func (self UniqueSet) Insert(k Stringable) UniqueSet {
|
|
|
|
self[k.String()] = struct{}{}
|
2014-09-15 02:10:50 +03:00
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
2014-09-15 16:42:12 +03:00
|
|
|
func (self UniqueSet) Include(k Stringable) bool {
|
|
|
|
_, ok := self[k.String()]
|
2014-09-15 02:10:50 +03:00
|
|
|
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func Set(s Settable) UniqueSet {
|
|
|
|
return s.AsSet()
|
|
|
|
}
|