diff options
Diffstat (limited to 'ethutil/set.go')
-rw-r--r-- | ethutil/set.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ethutil/set.go b/ethutil/set.go new file mode 100644 index 000000000..7955edac0 --- /dev/null +++ b/ethutil/set.go @@ -0,0 +1,36 @@ +package ethutil + +type Settable interface { + AsSet() UniqueSet +} + +type Stringable interface { + String() string +} + +type UniqueSet map[string]struct{} + +func NewSet(v ...Stringable) UniqueSet { + set := make(UniqueSet) + for _, val := range v { + set.Insert(val) + } + + return set +} + +func (self UniqueSet) Insert(k Stringable) UniqueSet { + self[k.String()] = struct{}{} + + return self +} + +func (self UniqueSet) Include(k Stringable) bool { + _, ok := self[k.String()] + + return ok +} + +func Set(s Settable) UniqueSet { + return s.AsSet() +} |