Traversor

package
v0.3.17 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BFS

func BFS[T any](tree *tr.Tree[T], init uc.Copier, f ObserverFunc[T]) error

BFS traverses the tree in breadth-first order.

Parameters:

  • t: The traversor.

Returns:

  • error: An error if the traversal fails.

func DFS

func DFS[T any](tree *tr.Tree[T], init uc.Copier, f ObserverFunc[T]) error

DFS traverses the tree in depth-first order.

Parameters:

  • t: The traversor.

Returns:

  • error: An error if the traversal fails.

Types

type Builder

type Builder[T any] struct {
	// contains filtered or unexported fields
}

Builder is a struct that builds a tree.

func (*Builder[T]) Build

func (b *Builder[T]) Build(elem T) (*tr.Tree[T], error)

MakeTree creates a tree from the given element.

Parameters:

  • elem: The element to start the tree from.
  • info: The info of the element.
  • f: The function that, given an element and info, returns the next elements. (i.e., the children of the element).

Returns:

  • *Tree[T]: The tree created from the element.
  • error: An error if the tree cannot be created.

Behaviors:

  • The 'info' parameter is copied for each node and it specifies the initial info before traversing the tree.

func (*Builder[T]) Reset

func (b *Builder[T]) Reset()

Reset resets the builder.

func (*Builder[T]) SetInfo

func (b *Builder[T]) SetInfo(info uc.Copier)

SetInfo sets the info of the builder.

Parameters:

  • info: The info to set.

func (*Builder[T]) SetNextFunc

func (b *Builder[T]) SetNextFunc(f NextsFunc[T])

SetNextFunc sets the next function of the builder.

Parameters:

  • f: The function to set.

type NextsFunc

type NextsFunc[T any] func(elem T, info uc.Copier) ([]T, error)

NextsFunc is a function that returns the next elements.

Parameters:

  • elem: The element to get the next elements from.
  • info: The info of the element.

Returns:

  • []T: A slice of the next elements.
  • error: An error if the function fails.

type ObserverFunc

type ObserverFunc[T any] func(data T, info uc.Copier) (bool, error)

ObserverFunc is a function that observes a node.

Parameters:

  • data: The data of the node.
  • info: The info of the node.

Returns:

  • bool: True if the traversal should continue, otherwise false.
  • error: An error if the observation fails.

Jump to

Keyboard shortcuts

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