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
ea4cf399
Unverified
Commit
ea4cf399
authored
Jul 24, 2019
by
Steven Allen
Committed by
GitHub
Jul 24, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #43 from ipfs/fix/with-root
fix: include root in searches by default
parents
89dd2ad2
f457eb47
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
9 deletions
+9
-9
merkledag.go
merkledag.go
+8
-8
merkledag_test.go
merkledag_test.go
+1
-1
No files found.
merkledag.go
View file @
ea4cf399
...
...
@@ -198,7 +198,7 @@ func FetchGraphWithDepthLimit(ctx context.Context, root cid.Cid, depthLim int, s
// If we have a ProgressTracker, we wrap the visit function to handle it
v
,
_
:=
ctx
.
Value
(
progressContextKey
)
.
(
*
ProgressTracker
)
if
v
==
nil
{
return
WalkDepth
(
ctx
,
GetLinksDirect
(
ng
),
root
,
visit
,
Concurrent
()
,
WithRoot
()
)
return
WalkDepth
(
ctx
,
GetLinksDirect
(
ng
),
root
,
visit
,
Concurrent
())
}
visitProgress
:=
func
(
c
cid
.
Cid
,
depth
int
)
bool
{
...
...
@@ -208,7 +208,7 @@ func FetchGraphWithDepthLimit(ctx context.Context, root cid.Cid, depthLim int, s
}
return
false
}
return
WalkDepth
(
ctx
,
GetLinksDirect
(
ng
),
root
,
visitProgress
,
Concurrent
()
,
WithRoot
()
)
return
WalkDepth
(
ctx
,
GetLinksDirect
(
ng
),
root
,
visitProgress
,
Concurrent
())
}
// GetMany gets many nodes from the DAG at once.
...
...
@@ -288,7 +288,7 @@ const defaultConcurrentFetch = 32
// walkOptions represent the parameters of a graph walking algorithm
type
walkOptions
struct
{
With
Root
bool
Skip
Root
bool
Concurrency
int
ErrorHandler
func
(
c
cid
.
Cid
,
err
error
)
error
}
...
...
@@ -306,10 +306,10 @@ func (wo *walkOptions) addHandler(handler func(c cid.Cid, err error) error) {
}
}
//
With
Root is a WalkOption indicating that the root node should
be visit
ed
func
With
Root
()
WalkOption
{
//
Skip
Root is a WalkOption indicating that the root node should
skipp
ed
func
Skip
Root
()
WalkOption
{
return
func
(
walkOptions
*
walkOptions
)
{
walkOptions
.
With
Root
=
true
walkOptions
.
Skip
Root
=
true
}
}
...
...
@@ -403,7 +403,7 @@ func WalkDepth(ctx context.Context, getLinks GetLinks, c cid.Cid, visit func(cid
}
func
sequentialWalkDepth
(
ctx
context
.
Context
,
getLinks
GetLinks
,
root
cid
.
Cid
,
depth
int
,
visit
func
(
cid
.
Cid
,
int
)
bool
,
options
*
walkOptions
)
error
{
if
depth
!=
0
||
options
.
WithRoot
{
if
!
(
options
.
SkipRoot
&&
depth
==
0
)
{
if
!
visit
(
root
,
depth
)
{
return
nil
}
...
...
@@ -484,7 +484,7 @@ func parallelWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, vis
var
shouldVisit
bool
// bypass the root if needed
if
depth
!=
0
||
options
.
WithRoot
{
if
!
(
options
.
SkipRoot
&&
depth
==
0
)
{
visitlk
.
Lock
()
shouldVisit
=
visit
(
ci
,
depth
)
visitlk
.
Unlock
()
...
...
merkledag_test.go
View file @
ea4cf399
...
...
@@ -386,7 +386,7 @@ func TestFetchGraphWithDepthLimit(t *testing.T) {
}
err
=
WalkDepth
(
context
.
Background
(),
offlineDS
.
GetLinks
,
root
.
Cid
(),
visitF
,
WithRoot
()
)
err
=
WalkDepth
(
context
.
Background
(),
offlineDS
.
GetLinks
,
root
.
Cid
(),
visitF
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
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