From 4db4ec1621767513ed2bd99d835c3e2f1c2b0e7e Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 15 Sep 2014 01:10:50 +0200 Subject: [PATCH] Added unique set --- ethutil/set.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ethutil/set.go diff --git a/ethutil/set.go b/ethutil/set.go new file mode 100644 index 0000000000..80e2edde29 --- /dev/null +++ b/ethutil/set.go @@ -0,0 +1,32 @@ +package ethutil + +type Settable interface { + AsSet() UniqueSet +} + +type UniqueSet map[interface{}]struct{} + +func NewSet(v ...interface{}) UniqueSet { + set := make(UniqueSet) + for _, val := range v { + set.Insert(val) + } + + return set +} + +func (self UniqueSet) Insert(k interface{}) UniqueSet { + self[k] = struct{}{} + + return self +} + +func (self UniqueSet) Include(k interface{}) bool { + _, ok := self[k] + + return ok +} + +func Set(s Settable) UniqueSet { + return s.AsSet() +}