-
Notifications
You must be signed in to change notification settings - Fork 197
/
dataTriesHolder.go
54 lines (43 loc) · 1.11 KB
/
dataTriesHolder.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
package state
import (
"sync"
"github.com/ElrondNetwork/elrond-go/data"
)
type dataTriesHolder struct {
tries map[string]data.Trie
mutex sync.RWMutex
}
// NewDataTriesHolder creates a new instance of dataTriesHolder
func NewDataTriesHolder() *dataTriesHolder {
return &dataTriesHolder{
tries: make(map[string]data.Trie),
}
}
// Put adds a trie pointer to the tries map
func (dth *dataTriesHolder) Put(key []byte, tr data.Trie) {
dth.mutex.Lock()
dth.tries[string(key)] = tr
dth.mutex.Unlock()
}
// Get returns the trie pointer that is stored in the map at the given key
func (dth *dataTriesHolder) Get(key []byte) data.Trie {
dth.mutex.Lock()
defer dth.mutex.Unlock()
return dth.tries[string(key)]
}
// GetAll returns all trie pointers from the map
func (dth *dataTriesHolder) GetAll() []data.Trie {
dth.mutex.Lock()
defer dth.mutex.Unlock()
tries := make([]data.Trie, 0)
for key := range dth.tries {
tries = append(tries, dth.tries[key])
}
return tries
}
// Reset clears the tries map
func (dth *dataTriesHolder) Reset() {
dth.mutex.Lock()
dth.tries = make(map[string]data.Trie)
dth.mutex.Unlock()
}