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