tree

package
v0.0.0-...-1ac790f Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyDFS

func ApplyDFS[N interface {
	Child() iter.Seq[N]
	BackwardChild() iter.Seq[N]

	TreeNoder
}, I any](t *Tree[N], trav Traverser[N, I]) (I, error)

ApplyDFS applies the DFS traversal logic to the tree.

Parameters:

  • t: The tree to apply the traversal logic to.
  • trav: The traverser that holds the traversal logic.

Returns:

  • error: The error that might occur during the traversal.

Types

type Traverser

type Traverser[N interface {
	Child() iter.Seq[N]

	BackwardChild() iter.Seq[N]

	TreeNoder
}, I any] struct {
	// InitFn is the function that initializes the traversal info.
	//
	// Parameters:
	//   - root: The root node of the tree.
	//
	// Returns:
	//   - I: The initial traversal info.
	InitFn func(root N) I

	// DoFn is the function that performs the traversal logic.
	//
	// Parameters:
	//   - info: The traversal info.
	//
	// Returns:
	//   - []I: The next traversal info.
	//   - error: The error that might occur during the traversal.
	DoFn func(info I) ([]I, error)
}

Traverser is the traverser that holds the traversal logic.

func PrintFn

func PrintFn[N interface {
	Child() iter.Seq[N]

	BackwardChild() iter.Seq[N]

	TreeNoder
}]() Traverser[N, *TreeStackElem[N]]

PrintFn returns the print function of the tree stringer.

Parameters:

  • root: The root node of the tree.

Returns:

  • Traverser[N, *TreeStackElem[N]]: The print function of the tree stringer.

type Tree

type Tree[T interface {
	Child() iter.Seq[T]

	BackwardChild() iter.Seq[T]

	TreeNoder
}] struct {
	// contains filtered or unexported fields
}

Tree is the tree data structure.

func NewTree

func NewTree[T interface {
	Child() iter.Seq[T]
	BackwardChild() iter.Seq[T]

	TreeNoder
}](root T) *Tree[T]

NewTree creates a new tree with the given root node.

Parameters:

  • root: The root node of the tree.

Returns:

  • *Tree[T]: The new tree. Never returns nil.

func (*Tree[T]) Clean

func (t *Tree[T]) Clean()

Clean implements the pkg.Type interface.

func (*Tree[T]) DeepCopy

func (t *Tree[T]) DeepCopy() pkg.Type

DeepCopy implements the pkg.Type interface.

func (*Tree[T]) Ensure

func (t *Tree[T]) Ensure()

Ensure implements the pkg.Type interface.

func (*Tree[T]) Equals

func (t *Tree[T]) Equals(other pkg.Type) bool

Equals implements the pkg.Type interface.

Two trees are equal if they have the same root node.

func (Tree[T]) Root

func (t Tree[T]) Root() T

Root returns the root node of the tree.

Returns:

  • T: The root node of the tree.

func (Tree[T]) String

func (t Tree[T]) String() string

String implements the fmt.Stringer interface.

type TreeNoder

type TreeNoder interface {
	// IsLeaf is a method that checks whether the node is a leaf node.
	//
	// Returns:
	//   - bool: True if the node is a leaf node, false otherwise.
	IsLeaf() bool

	comparable

	pkg.Type
}

TreeNoder is the interface that describes the behavior of a tree node.

type TreeStackElem

type TreeStackElem[N interface {
	Child() iter.Seq[N]

	BackwardChild() iter.Seq[N]

	TreeNoder
}] struct {
	// contains filtered or unexported fields
}

TreeStackElem is the stack element of the tree stringer.

func (TreeStackElem[N]) String

func (tse TreeStackElem[N]) String() string

String implements the fmt.Stringer interface.

type TreeStringTraverser

type TreeStringTraverser[N interface {
	Child() iter.Seq[N]

	BackwardChild() iter.Seq[N]

	TreeNoder
}] struct {
	// contains filtered or unexported fields
}

TreeStringTraverser is the tree stringer.

func (*TreeStringTraverser[N]) AppendLine

func (tst *TreeStringTraverser[N]) AppendLine(line string)

AppendLine is a helper function that appends a line to the tree stringer.

Parameters:

  • line: The line to append.

func (TreeStringTraverser[N]) IsSeen

func (tst TreeStringTraverser[N]) IsSeen(node N) bool

IsSeen is a helper function that checks if the node is seen.

Parameters:

  • node: The node to check.

Returns:

  • bool: The result of the check.

func (*TreeStringTraverser[N]) SetSeen

func (tst *TreeStringTraverser[N]) SetSeen(node N)

SetSeen is a helper function that sets the seen flag.

Parameters:

  • node: The node to set.

func (TreeStringTraverser[N]) String

func (tst TreeStringTraverser[N]) String() string

String implements the fmt.Stringer interface.

Jump to

Keyboard shortcuts

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