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]) Equals ¶
Equals implements the pkg.Type interface.
Two trees are equal if they have the same root node.
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.