-
Notifications
You must be signed in to change notification settings - Fork 5
/
node.go
62 lines (54 loc) · 1010 Bytes
/
node.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
package merkle
import "fmt"
type nodeKind int
const (
leaf nodeKind = iota
parent
)
type PartialNode struct {
index uint64
parent uint64
kind nodeKind
data []byte
}
type Node interface {
Index() uint64
Parent() uint64
Kind() nodeKind
Hash() []byte
Build(part PartialNode, hash []byte) Node
}
type DefaultNode struct {
index uint64
parent uint64
kind nodeKind
data []byte
hash []byte
}
func (dn DefaultNode) Index() uint64 {
return dn.index
}
func (dn DefaultNode) Parent() uint64 {
return dn.parent
}
func (dn DefaultNode) Data() []byte {
return dn.data
}
func (dn DefaultNode) Kind() nodeKind {
return dn.kind
}
func (dn DefaultNode) Hash() []byte {
return dn.hash
}
func (dn DefaultNode) Build(part PartialNode, hash []byte) Node {
return DefaultNode{
index: part.index,
parent: part.parent,
kind: part.kind,
data: part.data,
hash: hash,
}
}
func (dn DefaultNode) String() string {
return fmt.Sprintf("{Index: %d, Data: %s}", dn.index, dn.data)
}