-
Notifications
You must be signed in to change notification settings - Fork 175
/
times.go
61 lines (49 loc) · 1.19 KB
/
times.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// (c) 2019 Dapper Labs - ALL RIGHTS RESERVED
package stdmap
import (
"fmt"
"time"
"github.com/onflow/flow-go/model/flow"
)
// Times implements the times memory pool used to store time.Times for an idetifier to track transaction metrics in
// access nodes
type Times struct {
*Backend
}
// NewTimes creates a new memory pool for times
func NewTimes(limit uint) (*Times, error) {
t := &Times{
Backend: NewBackend(WithLimit(limit)),
}
return t, nil
}
type Time struct {
id flow.Identifier
ti time.Time
}
func (t *Time) ID() flow.Identifier {
return t.id
}
func (t *Time) Checksum() flow.Identifier {
return t.id
}
// Add adds a time to the mempool.
func (t *Times) Add(id flow.Identifier, ti time.Time) bool {
return t.Backend.Add(&Time{id, ti})
}
// ByID returns the time with the given ID from the mempool.
func (t *Times) ByID(id flow.Identifier) (time.Time, bool) {
entity, exists := t.Backend.ByID(id)
if !exists {
return time.Time{}, false
}
tt, ok := entity.(*Time)
if !ok {
panic(fmt.Sprintf("invalid entity in times pool (%T)", entity))
}
return tt.ti, true
}
// Rem removes the time with the given ID.
func (t *Times) Rem(id flow.Identifier) bool {
return t.Backend.Rem(id)
}