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