go-ipfs: github.com/ipfs/go-ipfs/dagutils Index | Files

package dagutils

import "github.com/ipfs/go-ipfs/dagutils"


Package Files

diff.go diffenum.go utils.go


const (
    Add = iota

These constants define the changes that can be applied to a DAG.

func ApplyChange Uses

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 Uses

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 Uses

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 Uses

func NewMemoryDagService() ipld.DAGService

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

type Change Uses

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 Uses

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.

func (*Change) String Uses

func (c *Change) String() string

String prints a human-friendly line about a change.

type Conflict Uses

type Conflict struct {
    A   *Change
    B   *Change

Conflict represents two incompatible changes and is returned by MergeDiffs().

type Editor Uses

type Editor struct {
    // contains filtered or unexported fields

Editor represents a ProtoNode tree editor and provides methods to modify it.

func NewDagEditor Uses

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 Uses

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 Uses

func (e *Editor) GetDagService() ipld.DAGService

GetDagService returns the DAGService used by this editor.

func (*Editor) GetNode Uses

func (e *Editor) GetNode() *dag.ProtoNode

GetNode returns the a copy of the root node being edited.

func (*Editor) InsertNodeAtPath Uses

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.

Package dagutils imports 14 packages (graph) and is imported by 35 packages. Updated 2019-08-09. Refresh now. Tools for package owners.