aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-09-15 07:10:50 +0800
committerobscuren <geffobscura@gmail.com>2014-09-15 07:10:50 +0800
commit4db4ec1621767513ed2bd99d835c3e2f1c2b0e7e (patch)
treea8ca8aac8b728b0347c8d464d7e9d7814e2d2d30
parent74ef22d8247c08b6b827f5e9f1001f8bcce9d0e0 (diff)
downloaddexon-4db4ec1621767513ed2bd99d835c3e2f1c2b0e7e.tar
dexon-4db4ec1621767513ed2bd99d835c3e2f1c2b0e7e.tar.gz
dexon-4db4ec1621767513ed2bd99d835c3e2f1c2b0e7e.tar.bz2
dexon-4db4ec1621767513ed2bd99d835c3e2f1c2b0e7e.tar.lz
dexon-4db4ec1621767513ed2bd99d835c3e2f1c2b0e7e.tar.xz
dexon-4db4ec1621767513ed2bd99d835c3e2f1c2b0e7e.tar.zst
dexon-4db4ec1621767513ed2bd99d835c3e2f1c2b0e7e.zip
Added unique set
-rw-r--r--ethutil/set.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/ethutil/set.go b/ethutil/set.go
new file mode 100644
index 000000000..80e2edde2
--- /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()
+}