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
b7d8fdef
Commit
b7d8fdef
authored
Feb 19, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hotfix: duplicate blocks werent being counted properly, deduped key list before requesting
parent
0c12b7a0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
+22
-2
merkledag.go
merkledag.go
+22
-2
No files found.
merkledag.go
View file @
b7d8fdef
...
...
@@ -180,17 +180,24 @@ func (ds *dagService) GetDAG(ctx context.Context, root *Node) []NodeGetter {
// GetNodes returns an array of 'NodeGetter' promises, with each corresponding
// to the key with the same index as the passed in keys
func
(
ds
*
dagService
)
GetNodes
(
ctx
context
.
Context
,
keys
[]
u
.
Key
)
[]
NodeGetter
{
// Early out if no work to do
if
len
(
keys
)
==
0
{
return
nil
}
promises
:=
make
([]
NodeGetter
,
len
(
keys
))
sendChans
:=
make
([]
chan
<-
*
Node
,
len
(
keys
))
for
i
,
_
:=
range
keys
{
promises
[
i
],
sendChans
[
i
]
=
newNodePromise
(
ctx
)
}
dedupedKeys
:=
dedupeKeys
(
keys
)
go
func
()
{
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
blkchan
:=
ds
.
Blocks
.
GetBlocks
(
ctx
,
k
eys
)
blkchan
:=
ds
.
Blocks
.
GetBlocks
(
ctx
,
dedupedK
eys
)
for
count
:=
0
;
count
<
len
(
keys
);
{
select
{
...
...
@@ -207,8 +214,8 @@ func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter {
}
is
:=
FindLinks
(
keys
,
blk
.
Key
(),
0
)
for
_
,
i
:=
range
is
{
sendChans
[
i
]
<-
nd
count
++
sendChans
[
i
]
<-
nd
}
case
<-
ctx
.
Done
()
:
return
...
...
@@ -218,6 +225,19 @@ func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter {
return
promises
}
// Remove duplicates from a list of keys
func
dedupeKeys
(
ks
[]
u
.
Key
)
[]
u
.
Key
{
kmap
:=
make
(
map
[
u
.
Key
]
struct
{})
var
out
[]
u
.
Key
for
_
,
k
:=
range
ks
{
if
_
,
ok
:=
kmap
[
k
];
!
ok
{
kmap
[
k
]
=
struct
{}{}
out
=
append
(
out
,
k
)
}
}
return
out
}
func
newNodePromise
(
ctx
context
.
Context
)
(
NodeGetter
,
chan
<-
*
Node
)
{
ch
:=
make
(
chan
*
Node
,
1
)
return
&
nodePromise
{
...
...
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