Documentation
¶
Index ¶
- Constants
- func ApplyChange(ctx context.Context, ds ipld.DAGService, nd *dag.ProtoNode, cs []*Change) (*dag.ProtoNode, error)
- func DiffEnumerate(ctx context.Context, dserv ipld.NodeGetter, from, to cid.Cid) error
- func MergeDiffs(a, b []*Change) ([]*Change, []Conflict)
- func NewMemoryDagService() ipld.DAGService
- type Change
- type Conflict
- type Editor
- func (e *Editor) Finalize(ctx context.Context, ds ipld.DAGService) (*dag.ProtoNode, error)
- func (e *Editor) GetDagService() ipld.DAGService
- func (e *Editor) GetNode() *dag.ProtoNode
- func (e *Editor) InsertNodeAtPath(ctx context.Context, pth string, toinsert ipld.Node, ...) error
- func (e *Editor) RmLink(ctx context.Context, pth string) error
Constants ¶
const (
Add = iota
Remove
Mod
)
These constants define the changes that can be applied to a DAG.
Variables ¶
This section is empty.
Functions ¶
func ApplyChange ¶
func ApplyChange(ctx context.Context, ds ipld.DAGService, nd *dag.ProtoNode, cs []*Change) (*dag.ProtoNode, error)
ApplyChange applies the requested changes to the given node in the given dag.
func DiffEnumerate ¶
func DiffEnumerate(ctx context.Context, dserv ipld.NodeGetter, from, to cid.Cid) error
DiffEnumerate fetches every object in the graph pointed to by 'to' that is not in 'from'. This can be used to more efficiently fetch a graph if you can guarantee you already have the entirety of 'from'
func MergeDiffs ¶
func MergeDiffs(a, b []*Change) ([]*Change, []Conflict)
MergeDiffs takes two slice of changes and adds them to a single slice. When a Change from b happens to the same path of an existing change in a, a conflict is created and b is not added to the merged slice. A slice of Conflicts is returned and contains pointers to the Changes involved (which share the same path).
func NewMemoryDagService ¶
func NewMemoryDagService() ipld.DAGService
NewMemoryDagService returns a new, thread-safe in-memory DAGService.
Types ¶
type Change ¶
type Change struct {
Type coreiface.ChangeType
Path string
Before cid.Cid
After cid.Cid
}
Change represents a change to a DAG and contains a reference to the old and new CIDs.
func Diff ¶
func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, error)
Diff returns a set of changes that transform node 'a' into node 'b'. It only traverses links in the following cases: 1. two node's links number are greater than 0. 2. both of two nodes are ProtoNode. Otherwise, it compares the cid and emits a Mod change object.
type Conflict ¶
type Conflict struct {
A *Change
B *Change
}
Conflict represents two incompatible changes and is returned by MergeDiffs().
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor represents a ProtoNode tree editor and provides methods to modify it.
func NewDagEditor ¶
func NewDagEditor(root *dag.ProtoNode, source ipld.DAGService) *Editor
NewDagEditor returns an ProtoNode editor.
* root is the node to be modified * source is the dagstore to pull nodes from (optional)
func (*Editor) Finalize ¶
func (e *Editor) Finalize(ctx context.Context, ds ipld.DAGService) (*dag.ProtoNode, error)
Finalize writes the new DAG to the given DAGService and returns the modified root node.
func (*Editor) GetDagService ¶
func (e *Editor) GetDagService() ipld.DAGService
GetDagService returns the DAGService used by this editor.
func (*Editor) GetNode ¶
func (e *Editor) GetNode() *dag.ProtoNode
GetNode returns the a copy of the root node being edited.
func (*Editor) InsertNodeAtPath ¶
func (e *Editor) InsertNodeAtPath(ctx context.Context, pth string, toinsert ipld.Node, create func() *dag.ProtoNode) error
InsertNodeAtPath inserts a new node in the tree and replaces the current root with the new one.