Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
71ede54b
Commit
71ede54b
authored
Oct 19, 2018
by
Overbool
Committed by
Lucas Molas
Jan 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(hamt): remove protonode
parent
071e19cf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
12 deletions
+18
-12
hamt/hamt.go
hamt/hamt.go
+18
-12
No files found.
hamt/hamt.go
View file @
71ede54b
...
...
@@ -44,10 +44,11 @@ func (ds *Shard) isValueNode() bool {
// A Shard represents the HAMT. It should be initialized with NewShard().
type
Shard
struct
{
nd
*
dag
.
ProtoNode
cid
cid
.
Cid
bitfield
bitfield
.
Bitfield
links
[]
*
ipld
.
Link
children
[]
*
Shard
tableSize
int
...
...
@@ -73,7 +74,7 @@ func NewShard(dserv ipld.DAGService, size int) (*Shard, error) {
return
nil
,
err
}
ds
.
nd
=
new
(
dag
.
ProtoNode
)
ds
.
links
=
make
([]
*
ipld
.
Link
,
0
)
ds
.
hashFunc
=
HashMurmur3
return
ds
,
nil
}
...
...
@@ -119,11 +120,16 @@ func NewHamtFromDag(dserv ipld.DAGService, nd ipld.Node) (*Shard, error) {
return
nil
,
err
}
ds
.
nd
=
pbnd
.
Copy
()
.
(
*
dag
.
ProtoNode
)
if
len
(
pbnd
.
Links
())
>
0
{
ds
.
links
=
make
([]
*
ipld
.
Link
,
len
(
pbnd
.
Links
()))
copy
(
ds
.
links
,
pbnd
.
Links
())
}
ds
.
cid
=
pbnd
.
Cid
()
ds
.
children
=
make
([]
*
Shard
,
len
(
pbnd
.
Links
()))
ds
.
bitfield
.
SetBytes
(
fsn
.
Data
())
ds
.
hashFunc
=
fsn
.
HashType
()
ds
.
builder
=
ds
.
nd
.
CidBuilder
()
ds
.
builder
=
pb
nd
.
CidBuilder
()
return
ds
,
nil
}
...
...
@@ -163,7 +169,7 @@ func (ds *Shard) Node() (ipld.Node, error) {
}
}
else
{
// child unloaded, just copy in link with updated name
lnk
:=
ds
.
nd
.
L
inks
()
[
cindex
]
lnk
:=
ds
.
l
inks
[
cindex
]
label
:=
lnk
.
Name
[
ds
.
maxpadlen
:
]
err
:=
out
.
AddRawLink
(
ds
.
linkNamePrefix
(
i
)
+
label
,
lnk
)
...
...
@@ -273,7 +279,7 @@ func (ds *Shard) getChild(ctx context.Context, i int) (*Shard, error) {
return
nil
,
fmt
.
Errorf
(
"invalid index passed to getChild (likely corrupt bitfield)"
)
}
if
len
(
ds
.
children
)
!=
len
(
ds
.
nd
.
L
inks
()
)
{
if
len
(
ds
.
children
)
!=
len
(
ds
.
l
inks
)
{
return
nil
,
fmt
.
Errorf
(
"inconsistent lengths between children array and Links array"
)
}
...
...
@@ -288,7 +294,7 @@ func (ds *Shard) getChild(ctx context.Context, i int) (*Shard, error) {
// loadChild reads the i'th child node of this shard from disk and returns it
// as a 'child' interface
func
(
ds
*
Shard
)
loadChild
(
ctx
context
.
Context
,
i
int
)
(
*
Shard
,
error
)
{
lnk
:=
ds
.
nd
.
L
inks
()
[
i
]
lnk
:=
ds
.
l
inks
[
i
]
lnkLinkType
,
err
:=
ds
.
childLinkType
(
lnk
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -356,20 +362,20 @@ func (ds *Shard) insertChild(idx int, key string, lnk *ipld.Link) error {
}
ds
.
children
=
append
(
ds
.
children
[
:
i
],
append
([]
*
Shard
{
sv
},
ds
.
children
[
i
:
]
...
)
...
)
ds
.
nd
.
SetL
inks
(
append
(
ds
.
nd
.
L
inks
()
[
:
i
],
append
([]
*
ipld
.
Link
{
nil
},
ds
.
nd
.
L
inks
()
[
i
:
]
...
)
...
)
)
ds
.
l
inks
=
append
(
ds
.
l
inks
[
:
i
],
append
([]
*
ipld
.
Link
{
nil
},
ds
.
l
inks
[
i
:
]
...
)
...
)
return
nil
}
func
(
ds
*
Shard
)
rmChild
(
i
int
)
error
{
if
i
<
0
||
i
>=
len
(
ds
.
children
)
||
i
>=
len
(
ds
.
nd
.
L
inks
()
)
{
if
i
<
0
||
i
>=
len
(
ds
.
children
)
||
i
>=
len
(
ds
.
l
inks
)
{
return
fmt
.
Errorf
(
"hamt: attempted to remove child with out of range index"
)
}
copy
(
ds
.
children
[
i
:
],
ds
.
children
[
i
+
1
:
])
ds
.
children
=
ds
.
children
[
:
len
(
ds
.
children
)
-
1
]
copy
(
ds
.
nd
.
L
inks
()
[
i
:
],
ds
.
nd
.
L
inks
()
[
i
+
1
:
])
ds
.
nd
.
SetLinks
(
ds
.
nd
.
L
inks
()
[
:
len
(
ds
.
nd
.
L
inks
()
)
-
1
]
)
copy
(
ds
.
l
inks
[
i
:
],
ds
.
l
inks
[
i
+
1
:
])
ds
.
links
=
ds
.
l
inks
[
:
len
(
ds
.
l
inks
)
-
1
]
return
nil
}
...
...
@@ -458,7 +464,7 @@ func makeAsyncTrieGetLinks(dagService ipld.DAGService, linkResults chan<- format
}
childShards
:=
make
([]
*
ipld
.
Link
,
0
,
len
(
directoryShard
.
children
))
links
:=
directoryShard
.
nd
.
L
inks
()
links
:=
directoryShard
.
l
inks
for
idx
:=
range
directoryShard
.
children
{
lnk
:=
links
[
idx
]
lnkLinkType
,
err
:=
directoryShard
.
childLinkType
(
lnk
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment