mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
Added unique set
This commit is contained in:
parent
74ef22d824
commit
4db4ec1621
32
ethutil/set.go
Normal file
32
ethutil/set.go
Normal file
@ -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()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user