dagutils

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MIT Imports: 13 Imported by: 38

Documentation

Index

Constants

This section is empty.

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   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.

func (*Change) String

func (c *Change) String() string

String prints a human-friendly line about a change.

type ChangeType

type ChangeType int

ChangeType denotes type of change in Change

const (
	Add ChangeType = iota
	Remove
	Mod
)

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

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.

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