github.com/koko1123/flow-go-1@v0.29.6/module/mempool/backData.go (about) 1 package mempool 2 3 import ( 4 "github.com/koko1123/flow-go-1/model/flow" 5 ) 6 7 // BackData represents the underlying data structure that is utilized by mempool.Backend, as the 8 // core structure of maintaining data on memory-pools. 9 // NOTE: BackData by default is not expected to provide concurrency-safe operations. As it is just the 10 // model layer of the mempool, the safety against concurrent operations are guaranteed by the Backend that 11 // is the control layer. 12 type BackData interface { 13 // Has checks if backdata already contains the entity with the given identifier. 14 Has(entityID flow.Identifier) bool 15 16 // Add adds the given entity to the backdata. 17 Add(entityID flow.Identifier, entity flow.Entity) bool 18 19 // Remove removes the entity with the given identifier. 20 Remove(entityID flow.Identifier) (flow.Entity, bool) 21 22 // Adjust adjusts the entity using the given function if the given identifier can be found. 23 // Returns a bool which indicates whether the entity was updated as well as the updated entity. 24 Adjust(entityID flow.Identifier, f func(flow.Entity) flow.Entity) (flow.Entity, bool) 25 26 // ByID returns the given entity from the backdata. 27 ByID(entityID flow.Identifier) (flow.Entity, bool) 28 29 // Size returns the size of the backdata, i.e., total number of stored (entityId, entity) pairs. 30 Size() uint 31 32 // All returns all entities stored in the backdata. 33 All() map[flow.Identifier]flow.Entity 34 35 // Identifiers returns the list of identifiers of entities stored in the backdata. 36 Identifiers() flow.IdentifierList 37 38 // Entities returns the list of entities stored in the backdata. 39 Entities() []flow.Entity 40 41 // Clear removes all entities from the backdata. 42 Clear() 43 }