tree

package
v1.34.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	// unique id for the node
	ID string
	// contains filtered or unexported fields
}

Node : a basic node in a tree

func NewNode

func NewNode(id string) *Node

NewNode : create a node

func (*Node) AddChild

func (n *Node) AddChild(child *Node) bool

AddChild : add a child to this node; return false if child already exists

func (*Node) GetChildren

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

GetChildren : the children of this node

func (*Node) GetHeight

func (n *Node) GetHeight() int

GetHeight : the height of this node in the tree

func (*Node) GetID

func (n *Node) GetID() string

GetID : the unique ID of this node

func (*Node) GetLeaves

func (n *Node) GetLeaves() []*Node

GetLeaves : the leaf nodes in the subtree consisting of this node as a root

func (*Node) GetNumChildren

func (n *Node) GetNumChildren() int

GetNumChildren : the number of children of this node

func (*Node) GetParent

func (n *Node) GetParent() *Node

GetParent : the parent of this node

func (*Node) GetPathToRoot

func (n *Node) GetPathToRoot() []*Node

GetPathToRoot : the path from this node to the root of the tree; node (root) is first (last) in list

func (*Node) GetValue

func (n *Node) GetValue() int

GetValue : the value of this node

func (*Node) HasLeaf

func (n *Node) HasLeaf(leafID string) bool

HasLeaf : does the subtree from this node has a given node as a leaf

func (*Node) IsLeaf

func (n *Node) IsLeaf() bool

IsLeaf : is this node a leaf in the tree

func (*Node) IsRoot

func (n *Node) IsRoot() bool

IsRoot : is this node the root of the tree

func (*Node) RemoveChild

func (n *Node) RemoveChild(child *Node) bool

RemoveChild : remove a child from this node

func (*Node) SetValue

func (n *Node) SetValue(value int)

SetValue : set the value of this node

func (*Node) String

func (n *Node) String() string

String : a print out of the node; e.g. A -> ( C -> ( D ) B )

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

Tree : a basic tree

func NewTree

func NewTree(root *Node) *Tree

NewTree : create a tree

func (*Tree) GetHeight

func (t *Tree) GetHeight() int

GetHeight : the height of the tree

func (*Tree) GetLeafIDs

func (t *Tree) GetLeafIDs() []string

GetLeafIDs : the IDs of the leaves of the tree

func (*Tree) GetLeafNode

func (t *Tree) GetLeafNode(nodeID string) *Node

GetLeafNode : get a leaf node by ID; null if not found

func (*Tree) GetLeaves

func (t *Tree) GetLeaves() []*Node

GetLeaves : the leaves of the tree

func (*Tree) GetNode

func (t *Tree) GetNode(nodeID string) *Node

GetNode : find node in tree with a given ID; null if not found

func (*Tree) GetNodeIDs

func (t *Tree) GetNodeIDs() []string

GetNodeIDs : get (sorted) IDs of all nodes in the tree

func (*Tree) GetNodeListBFS

func (t *Tree) GetNodeListBFS() []*Node

GetNodeListBFS : list of nodes in BFS order

func (*Tree) GetRoot

func (t *Tree) GetRoot() *Node

GetRoot : the root of the tree

func (*Tree) String

func (t *Tree) String() string

String : a print out of the tree

Jump to

Keyboard shortcuts

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