tree

package
v0.0.0-...-881dfb5 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

tree package defines methods that generates tree of specified shape.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FullTree

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

FullTree is a tree where each non-leaf vertex has N children. N is the degree. For a full tree of height H and degree D, the total number of vertices is `(D^H -1)/(D-1)`.

func NewFullTree

func NewFullTree(height int, degree int) (*FullTree, error)

NewFullTree creates a full tree of height and degree.

func (*FullTree) Degree

func (t *FullTree) Degree() int

func (*FullTree) Height

func (t *FullTree) Height() int

func (*FullTree) Root

func (t *FullTree) Root() *Vertex

func (*FullTree) Size

func (t *FullTree) Size() int

type Tree

type Tree interface {
	Root() *Vertex
	Size() int
}

type Vertex

type Vertex struct {
	// BFS order of the node in the tree. starting from 0.
	Order int

	// Level of the node in the tree. Root has level 0.
	Level int

	Children []*Vertex
	Parent   *Vertex

	// The next node in BFS order.
	Next *Vertex
}

Vertex is a general vertex in a tree. Each vertex records information of its positional information in a tree. For simplicity, a leaf has empty Children[], instead a non-empty Children[] where each item in Children[] being nil.

func (*Vertex) IsInternal

func (v *Vertex) IsInternal() bool

func (*Vertex) IsLeaf

func (v *Vertex) IsLeaf() bool

func (*Vertex) IsRoot

func (v *Vertex) IsRoot() bool

Jump to

Keyboard shortcuts

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