ipld-eth-db-validator/integration/util_test.go

37 lines
629 B
Go
Raw Normal View History

package integration_test
import (
"sync"
)
type atomicBlockSet struct {
blocks map[uint64]struct{}
2023-08-11 07:57:58 +00:00
sync.RWMutex
}
func newBlockSet() *atomicBlockSet {
return &atomicBlockSet{blocks: make(map[uint64]struct{})}
}
func (set *atomicBlockSet) contains(block uint64) bool {
2023-08-11 07:57:58 +00:00
set.RLock()
defer set.RUnlock()
_, has := set.blocks[block]
return has
}
func (set *atomicBlockSet) containsAll(blocks []uint64) bool {
for _, block := range blocks {
if !set.contains(block) {
return false
}
}
return true
}
func (set *atomicBlockSet) add(block uint64) {
set.Lock()
defer set.Unlock()
set.blocks[block] = struct{}{}
}