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
b54c4fa0
Commit
b54c4fa0
authored
Nov 13, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improves memory usage of add
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
64ec8e46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
+17
-2
merkledag.go
merkledag.go
+11
-2
utils/utils.go
utils/utils.go
+6
-0
No files found.
merkledag.go
View file @
b54c4fa0
...
@@ -20,6 +20,7 @@ type DAGService interface {
...
@@ -20,6 +20,7 @@ type DAGService interface {
AddRecursive
(
*
Node
)
error
AddRecursive
(
*
Node
)
error
Get
(
context
.
Context
,
key
.
Key
)
(
*
Node
,
error
)
Get
(
context
.
Context
,
key
.
Key
)
(
*
Node
,
error
)
Remove
(
*
Node
)
error
Remove
(
*
Node
)
error
RemoveRecursive
(
*
Node
)
error
// GetDAG returns, in order, all the single leve child
// GetDAG returns, in order, all the single leve child
// nodes of the passed in node.
// nodes of the passed in node.
...
@@ -107,10 +108,10 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {
...
@@ -107,10 +108,10 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {
}
}
// Remove deletes the given node and all of its children from the BlockService
// Remove deletes the given node and all of its children from the BlockService
func
(
n
*
dagService
)
Remove
(
nd
*
Node
)
error
{
func
(
n
*
dagService
)
Remove
Recursive
(
nd
*
Node
)
error
{
for
_
,
l
:=
range
nd
.
Links
{
for
_
,
l
:=
range
nd
.
Links
{
if
l
.
Node
!=
nil
{
if
l
.
Node
!=
nil
{
n
.
Remove
(
l
.
Node
)
n
.
Remove
Recursive
(
l
.
Node
)
}
}
}
}
k
,
err
:=
nd
.
Key
()
k
,
err
:=
nd
.
Key
()
...
@@ -120,6 +121,14 @@ func (n *dagService) Remove(nd *Node) error {
...
@@ -120,6 +121,14 @@ func (n *dagService) Remove(nd *Node) error {
return
n
.
Blocks
.
DeleteBlock
(
k
)
return
n
.
Blocks
.
DeleteBlock
(
k
)
}
}
func
(
n
*
dagService
)
Remove
(
nd
*
Node
)
error
{
k
,
err
:=
nd
.
Key
()
if
err
!=
nil
{
return
err
}
return
n
.
Blocks
.
DeleteBlock
(
k
)
}
// FetchGraph fetches all nodes that are children of the given node
// FetchGraph fetches all nodes that are children of the given node
func
FetchGraph
(
ctx
context
.
Context
,
root
*
Node
,
serv
DAGService
)
error
{
func
FetchGraph
(
ctx
context
.
Context
,
root
*
Node
,
serv
DAGService
)
error
{
return
EnumerateChildrenAsync
(
ctx
,
serv
,
root
,
key
.
NewKeySet
())
return
EnumerateChildrenAsync
(
ctx
,
serv
,
root
,
key
.
NewKeySet
())
...
...
utils/utils.go
View file @
b54c4fa0
...
@@ -40,6 +40,8 @@ func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname s
...
@@ -40,6 +40,8 @@ func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname s
return
nil
,
err
return
nil
,
err
}
}
_
=
ds
.
Remove
(
root
)
// ensure no link with that name already exists
// ensure no link with that name already exists
_
=
root
.
RemoveNodeLink
(
childname
)
// ignore error, only option is ErrNotFound
_
=
root
.
RemoveNodeLink
(
childname
)
// ignore error, only option is ErrNotFound
...
@@ -83,6 +85,8 @@ func insertNodeAtPath(ctx context.Context, ds dag.DAGService, root *dag.Node, pa
...
@@ -83,6 +85,8 @@ func insertNodeAtPath(ctx context.Context, ds dag.DAGService, root *dag.Node, pa
return
nil
,
err
return
nil
,
err
}
}
_
=
ds
.
Remove
(
root
)
_
=
root
.
RemoveNodeLink
(
path
[
0
])
_
=
root
.
RemoveNodeLink
(
path
[
0
])
err
=
root
.
AddNodeLinkClean
(
path
[
0
],
ndprime
)
err
=
root
.
AddNodeLinkClean
(
path
[
0
],
ndprime
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -133,6 +137,8 @@ func rmLink(ctx context.Context, ds dag.DAGService, root *dag.Node, path []strin
...
@@ -133,6 +137,8 @@ func rmLink(ctx context.Context, ds dag.DAGService, root *dag.Node, path []strin
return
nil
,
err
return
nil
,
err
}
}
_
=
ds
.
Remove
(
root
)
_
=
root
.
RemoveNodeLink
(
path
[
0
])
_
=
root
.
RemoveNodeLink
(
path
[
0
])
err
=
root
.
AddNodeLinkClean
(
path
[
0
],
nnode
)
err
=
root
.
AddNodeLinkClean
(
path
[
0
],
nnode
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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