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
eba3c6bd
Commit
eba3c6bd
authored
Nov 24, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix issues in merkledag
parent
c52fb3be
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
12 deletions
+23
-12
merkledag.go
merkledag.go
+23
-12
No files found.
merkledag.go
View file @
eba3c6bd
...
...
@@ -163,17 +163,6 @@ func (n *Node) Multihash() (mh.Multihash, error) {
return
n
.
cached
,
nil
}
// Searches this nodes links for one to the given key,
// returns the index of said link
func
(
n
*
Node
)
FindLink
(
k
u
.
Key
)
(
int
,
error
)
{
for
i
,
lnk
:=
range
n
.
Links
{
if
u
.
Key
(
lnk
.
Hash
)
==
k
{
return
i
,
nil
}
}
return
-
1
,
u
.
ErrNotFound
}
// Key returns the Multihash as a key, for maps.
func
(
n
*
Node
)
Key
()
(
u
.
Key
,
error
)
{
h
,
err
:=
n
.
Multihash
()
...
...
@@ -298,6 +287,17 @@ func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{}
return
done
}
// Searches this nodes links for one to the given key,
// returns the index of said link
func
FindLink
(
n
*
Node
,
k
u
.
Key
,
found
[]
*
Node
)
(
int
,
error
)
{
for
i
,
lnk
:=
range
n
.
Links
{
if
u
.
Key
(
lnk
.
Hash
)
==
k
&&
found
[
i
]
==
nil
{
return
i
,
nil
}
}
return
-
1
,
u
.
ErrNotFound
}
// BatchFetch will fill out all of the links of the given Node.
// It returns a channel of nodes, which the caller can receive
// all the child nodes of 'root' on, in proper order.
...
...
@@ -324,7 +324,7 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
count
:=
0
for
blk
:=
range
blkchan
{
count
++
i
,
err
:=
root
.
FindLink
(
blk
.
Key
())
i
,
err
:=
FindLink
(
root
,
blk
.
Key
()
,
nodes
)
if
err
!=
nil
{
panic
(
"Received block that wasnt in this nodes links!"
)
}
...
...
@@ -356,3 +356,14 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
return
sig
}
func
checkForDupes
(
ks
[]
u
.
Key
)
bool
{
seen
:=
make
(
map
[
u
.
Key
]
struct
{})
for
_
,
k
:=
range
ks
{
if
_
,
ok
:=
seen
[
k
];
ok
{
return
true
}
seen
[
k
]
=
struct
{}{}
}
return
false
}
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