tree

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: MIT Imports: 3 Imported by: 0

README

Tree

A dumb implementation of a general (and sort of generic) tree data structure.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	Value    interface{}
	Parent   *Node
	Children []*Node
}

Node is the data structure which the tree is consists of

func (*Node) Add

func (node *Node) Add(value interface{}) *Node

Add adds a new node under the receiving node with the specified value

func (*Node) ForEachDFS

func (node *Node) ForEachDFS(callback func(*Node))

ForEachDFS runs callback for each node using depth-first-search

func (*Node) HasChildren

func (node *Node) HasChildren() bool

HasChildren returns true if node has any child nodes

func (*Node) Remove

func (node *Node) Remove()

Remove this node from the tree and all its descdendants

func (*Node) String

func (node *Node) String() string

type Tree

type Tree struct {
	Root *Node
}

Tree represent a tree structure and holds a reference to the root

func Create

func Create(value interface{}) *Tree

Create returns a new empty tree

func (*Tree) ForEachBSF

func (tree *Tree) ForEachBSF(callback func(*Node))

ForEachBSF iterates over this tree using breadth first search and calls callback for each node

func (*Tree) Size

func (tree *Tree) Size() int

Size returns the number of nodes in the tree, the root excluded

func (*Tree) String

func (tree *Tree) String() string

Implement the fmt.Stringer interface

Directories

Path Synopsis
examples
locations command

Jump to

Keyboard shortcuts

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