tree

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2022 License: BSD-3-Clause Imports: 0 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterFunc

type FilterFunc func(NodeIFace) bool

FilterFunc signature for filter functions

type FilterVisitor

type FilterVisitor struct {
	VisitorIFace
	// contains filtered or unexported fields
}

FilterVisitor is a visitor that filters nodes

func (*FilterVisitor) Visit

func (v *FilterVisitor) Visit(n NodeIFace) interface{}

Visit filters nodes (pre-order traversal) that match the filter and returns []NodeIFace

type LeafVisitor

type LeafVisitor struct {
	VisitorIFace
}

LeafVisitor returns the leaves of a tree

func (*LeafVisitor) Visit

func (v *LeafVisitor) Visit(n NodeIFace) interface{}

Visit returns []NodeIFace of leaves on the tree

type Node

type Node struct {
	NodeIFace
	// contains filtered or unexported fields
}

Node is a Tree Node

func (*Node) Accept

func (n *Node) Accept(v VisitorIFace) interface{}

func (*Node) AddChild

func (n *Node) AddChild(c NodeIFace) NodeIFace

func (*Node) GetAncestors

func (n *Node) GetAncestors() []NodeIFace

func (*Node) GetAncestorsAndSelf

func (n *Node) GetAncestorsAndSelf() []NodeIFace

func (*Node) GetChildren

func (n *Node) GetChildren() []NodeIFace

func (*Node) GetDepth

func (n *Node) GetDepth() int

func (*Node) GetHeight

func (n *Node) GetHeight() int

func (*Node) GetParent

func (n *Node) GetParent() NodeIFace

func (*Node) GetSiblings

func (n *Node) GetSiblings() []NodeIFace

func (*Node) GetSiblingsAndSelf

func (n *Node) GetSiblingsAndSelf() []NodeIFace

func (*Node) GetSize

func (n *Node) GetSize() int

func (*Node) GetValue

func (n *Node) GetValue() interface{}

func (*Node) IsChild

func (n *Node) IsChild() bool

func (*Node) IsLeaf

func (n *Node) IsLeaf() bool

func (*Node) IsRoot

func (n *Node) IsRoot() bool

func (*Node) RemoveAllChildren

func (n *Node) RemoveAllChildren() NodeIFace

func (*Node) RemoveChild

func (n *Node) RemoveChild(c NodeIFace) NodeIFace

func (*Node) SetChildren

func (n *Node) SetChildren(c ...NodeIFace) NodeIFace

func (*Node) SetParent

func (n *Node) SetParent(p NodeIFace) NodeIFace

func (*Node) SetValue

func (n *Node) SetValue(v interface{}) NodeIFace

type NodeIFace

type NodeIFace interface {
	//SetValue sets the value of this node and returns this node
	SetValue(v interface{}) NodeIFace
	//GetValue returns the value of this node
	GetValue() interface{}
	//AddChild adds a child to the set of children for this node and returns this node
	AddChild(NodeIFace) NodeIFace
	//RemoveChild removes the child node matching the input parameter and returns this node
	RemoveChild(NodeIFace) NodeIFace
	//RemoveAllChildren removes all child nodes of this node (and their children) and returns this node
	RemoveAllChildren() NodeIFace
	//GetChildren returns all child nodes of this node
	GetChildren() []NodeIFace
	//SetChildren replaces all child nodes of this node with new ones and returns this node
	SetChildren(...NodeIFace) NodeIFace
	//SetParent sets the parent of this node and returns this node
	SetParent(NodeIFace) NodeIFace
	//GetParent returns the parent node of this node or nil if none
	GetParent() NodeIFace
	//GetAncestors retrieves all ancestors of node excluding current node
	GetAncestors() []NodeIFace
	//GetAncestorsAndSelf retrieves all ancestors of node as well as the node itself
	GetAncestorsAndSelf() []NodeIFace
	//GetSiblings retrieves all neighboring nodes (children of same parent), excluding the current node
	GetSiblings() []NodeIFace
	//GetSiblingsAndSelf returns all neighboring nodes (children of same parent), including the current node
	GetSiblingsAndSelf() []NodeIFace
	//IsRoot returns true if the node is the root, false otherwise
	IsRoot() bool
	//IsChild returns true if the node is a child, false otherwise
	IsChild() bool
	//IsLeaf  returns true if the node is a leaf node, false otherwise
	IsLeaf() bool
	//GetDepth returns the distance from the current node to the root
	GetDepth() int
	//GetHeight returns the height of the tree whose root is this node
	GetHeight() int
	//GetSize returns the number of nodes in the tree rooted at this node
	GetSize() int
	//Accept Accept method for the visitor pattern (see http://en.wikipedia.org/wiki/Visitor_pattern)
	Accept(v VisitorIFace) interface{}
}

NodeIFace an interface for a Tree Node

func NewNode

func NewNode(v interface{}, children *[]NodeIFace) NodeIFace

NewNode returns a new Node

type PostOrderVisitor

type PostOrderVisitor struct {
	VisitorIFace
}

PostOrderVisitor walks a tree in post-order

func (*PostOrderVisitor) Visit

func (v *PostOrderVisitor) Visit(n NodeIFace) interface{}

Visit returns []NodeIFace in post order

type PreOrderVisitor

type PreOrderVisitor struct {
	VisitorIFace
}

PreOrderVisitor walks a tree in pre-order

func (*PreOrderVisitor) Visit

func (v *PreOrderVisitor) Visit(n NodeIFace) interface{}

Visit returns []NodeIFace in pre order

type VisitorIFace

type VisitorIFace interface {
	//Visit visits each node starting at given node
	Visit(NodeIFace) interface{}
}

VisitorIFace Visitor interface for Nodes

func NewFilterVisitor

func NewFilterVisitor(filter FilterFunc) VisitorIFace

NewFilterVisitor returns a FilterVisitor

func NewLeafVisitor

func NewLeafVisitor() VisitorIFace

func NewPostOrderVisitor

func NewPostOrderVisitor() VisitorIFace

func NewPreOrderVisitor

func NewPreOrderVisitor() VisitorIFace

Jump to

Keyboard shortcuts

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