-
Notifications
You must be signed in to change notification settings - Fork 39
/
trie.go
99 lines (87 loc) · 2.22 KB
/
trie.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package trie
import (
"reflect"
"github.com/icon-project/goloop/common/db"
"github.com/icon-project/goloop/common/merkle"
)
type (
/*
*/
Immutable interface {
Empty() bool
// Get returns the value stored under the specified key, or nil if the key doesn't exist.
Get(k []byte) ([]byte, error)
Hash() []byte // return nil if this Tree is empty
GetProof(k []byte) [][]byte // return nill of this Tree is empty
Iterator() Iterator
Filter(prefix []byte) Iterator
Equal(immutable Immutable, exact bool) bool
Prove(k []byte, p [][]byte) ([]byte, error)
Resolve(builder merkle.Builder)
ClearCache()
Database() db.Database
}
Snapshot interface {
Immutable
Flush() error
}
Iterator interface {
Next() error
Has() bool
Get() (value []byte, key []byte, err error)
}
Mutable interface {
Get(k []byte) ([]byte, error)
Set(k, v []byte) ([]byte, error)
Delete(k []byte) ([]byte, error)
GetSnapshot() Snapshot
Reset(d Immutable) error
ClearCache()
Database() db.Database
}
Object interface {
Bytes() []byte
Reset(s db.Database, k []byte) error
Flush() error
Equal(Object) bool
Resolve(builder merkle.Builder) error
ClearCache()
}
IteratorForObject interface {
Next() error
Has() bool
Get() (Object, []byte, error)
}
ImmutableForObject interface {
Empty() bool
Get(k []byte) (Object, error)
Hash() []byte
GetProof(k []byte) [][]byte // return nill of this Tree is empty
Iterator() IteratorForObject
Filter(prefix []byte) IteratorForObject
Equal(object ImmutableForObject, exact bool) bool
Prove(k []byte, p [][]byte) (Object, error)
Resolve(builder merkle.Builder)
ClearCache()
Database() db.Database
}
SnapshotForObject interface {
ImmutableForObject
Flush() error
}
MutableForObject interface {
Get(k []byte) (Object, error)
Set(k []byte, o Object) (Object, error)
Delete(k []byte) (Object, error)
GetSnapshot() SnapshotForObject
Reset(s ImmutableForObject)
ClearCache()
Database() db.Database
}
Manager interface {
NewImmutable(rootHash []byte) Immutable
NewMutable(rootHash []byte) Mutable
NewImmutableForObject(h []byte, t reflect.Type) ImmutableForObject
NewMutableForObject(h []byte, t reflect.Type) MutableForObject
}
)