dagutils

package
v0.4.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
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 added in v0.3.8

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 added in v0.4.10

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 added in v0.3.8

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 added in v0.4.0

func NewMemoryDagService() ipld.DAGService

NewMemoryDagService returns a new, thread-safe in-memory DAGService.

Types

type Change added in v0.3.8

type Change struct {
	Type   int
	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 added in v0.3.8

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'

func (*Change) String added in v0.3.8

func (c *Change) String() string

String prints a human-friendly line about a change.

type Conflict added in v0.3.8

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 added in v0.4.0

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 added in v0.3.8

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.

func (e *Editor) RmLink(ctx context.Context, pth string) error

RmLink removes the link with the given name and updates the root node of the editor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL