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