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-merkledag
Commits
b22eae6b
Commit
b22eae6b
authored
Nov 02, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set data and links nil if not present
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
6ccb17a4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
8 deletions
+16
-8
coding.go
coding.go
+6
-2
node.go
node.go
+8
-4
utils/utils_test.go
utils/utils_test.go
+2
-2
No files found.
coding.go
View file @
b22eae6b
...
...
@@ -50,7 +50,9 @@ func (n *Node) Marshal() ([]byte, error) {
func
(
n
*
Node
)
getPBNode
()
*
pb
.
PBNode
{
pbn
:=
&
pb
.
PBNode
{}
if
len
(
n
.
Links
)
>
0
{
pbn
.
Links
=
make
([]
*
pb
.
PBLink
,
len
(
n
.
Links
))
}
sort
.
Stable
(
LinkSlice
(
n
.
Links
))
// keep links sorted
for
i
,
l
:=
range
n
.
Links
{
...
...
@@ -60,7 +62,9 @@ func (n *Node) getPBNode() *pb.PBNode {
pbn
.
Links
[
i
]
.
Hash
=
[]
byte
(
l
.
Hash
)
}
if
len
(
n
.
Data
)
>
0
{
pbn
.
Data
=
n
.
Data
}
return
pbn
}
...
...
node.go
View file @
b22eae6b
...
...
@@ -176,11 +176,15 @@ func (n *Node) GetLinkedNode(ctx context.Context, ds DAGService, name string) (*
// NOTE: does not make copies of Node objects in the links.
func
(
n
*
Node
)
Copy
()
*
Node
{
nnode
:=
new
(
Node
)
if
len
(
n
.
Data
)
>
0
{
nnode
.
Data
=
make
([]
byte
,
len
(
n
.
Data
))
copy
(
nnode
.
Data
,
n
.
Data
)
}
if
len
(
n
.
Links
)
>
0
{
nnode
.
Links
=
make
([]
*
Link
,
len
(
n
.
Links
))
copy
(
nnode
.
Links
,
n
.
Links
)
}
return
nnode
}
...
...
utils/utils_test.go
View file @
b22eae6b
...
...
@@ -85,8 +85,8 @@ func TestInsertNode(t *testing.T) {
t
.
Fatal
(
err
)
}
if
k
.
B58String
()
!=
"Qm
ThorWojP6YzLJwDukxiYCoKQSwyrMCvdt4WZ6rPm221
t"
{
t
.
Fatal
(
"output was different than expected
"
)
if
k
.
B58String
()
!=
"Qm
Z8yeT9uD6ouJPNAYt62XffYuXBT6b4mP4obRSE9cJrS
t"
{
t
.
Fatal
(
"output was different than expected
: "
,
k
)
}
}
...
...
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