-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathlink.go
More file actions
43 lines (36 loc) · 729 Bytes
/
link.go
File metadata and controls
43 lines (36 loc) · 729 Bytes
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
package amt
import (
"context"
"github.com/filecoin-project/go-amt-ipld/v4/internal"
cid "github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
)
type link struct {
cid cid.Cid
cached *node
dirty bool
}
func (l *link) load(ctx context.Context, bs cbor.IpldStore, bitWidth uint, height int) (*node, error) {
if l.cached == nil {
var nd internal.Node
if err := bs.Get(ctx, l.cid, &nd); err != nil {
return nil, err
}
n, err := newNode(nd, bitWidth, false, height == 0)
if err != nil {
return nil, err
}
l.cached = n
}
return l.cached, nil
}
func (l *link) clone() *link {
if l == nil {
return nil
}
return &link{
cid: l.cid,
cached: l.cached.clone(),
dirty: l.dirty,
}
}