github.com/ava-labs/avalanchego@v1.11.11/pubsub/bloom/map_filter.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package bloom 5 6 import ( 7 "sync" 8 9 "github.com/ava-labs/avalanchego/utils/set" 10 ) 11 12 type mapFilter struct { 13 lock sync.RWMutex 14 values set.Set[string] 15 } 16 17 func NewMap() Filter { 18 return &mapFilter{} 19 } 20 21 func (m *mapFilter) Add(bl ...[]byte) { 22 m.lock.Lock() 23 defer m.lock.Unlock() 24 25 for _, b := range bl { 26 m.values.Add(string(b)) 27 } 28 } 29 30 func (m *mapFilter) Check(b []byte) bool { 31 m.lock.RLock() 32 defer m.lock.RUnlock() 33 34 return m.values.Contains(string(b)) 35 }