traverse

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2015 License: MIT Imports: 2 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 *mdag.Node, o Options) error

Types

type ErrFunc

type ErrFunc func(err error) error

If there is a problem walking to the Node, and ErrFunc is provided, 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     mdag.DAGService // 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  Order = iota // depth-first pre-order
	DFSPost              // depth-first post-order
	BFS                  // breadth-first
)

type State

type State struct {
	Node  *mdag.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