traverse

package
v0.4.15-rc1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package traverse provides merkledag traversal functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Traverse

func Traverse(root ipld.Node, o Options) error

Traverse initiates a DAG traversal with the given options starting at the given root.

Types

type ErrFunc

type ErrFunc func(err error) error

ErrFunc is provided to handle problems when walking to the Node. Traverse will call ErrFunc with the error encountered. ErrFunc can decide how to handle that error, and return an error back to Traversal with how to proceed:

  • nil - skip the Node and its children, but continue processing
  • all other errors halt processing immediately.

If ErrFunc is nil, Traversal will stop, as if:

opts.ErrFunc = func(err error) { return err }

type Func

type Func func(current State) error

Func is the type of the function called for each dag.Node visited by Traverse. The traversal argument contains the current traversal state. If an error is returned, processing stops.

type Options

type Options struct {
	DAG     ipld.NodeGetter // the dagservice to fetch nodes
	Order   Order           // what order to traverse in
	Func    Func            // the function to perform at each step
	ErrFunc ErrFunc         // see ErrFunc. Optional

	SkipDuplicates bool // whether to skip duplicate nodes
}

Options specifies a series of traversal options

type Order

type Order int

Order is an identifier for traversal algorithm orders

const (
	// DFSPre defines depth-first pre-order
	DFSPre Order = iota
	// DFSPost defines depth-first post-order
	DFSPost
	// BFS defines breadth-first order
	BFS
)

These constants define different traversing methods

type State

type State struct {
	Node  ipld.Node
	Depth int
}

State is a current traversal state

Jump to

Keyboard shortcuts

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