tree

package module
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 6 Imported by: 2

README

tree

A Go package used for generating first child/next sibling tree nodes. It also features some already generated tree nodes and operations on trees.

Table of Contents

  1. Table of Contents
  2. Tool
  3. Documentation
  4. Content

Tool

Installation

To install the tool, run the following command:

go get -u github.com/PlayerR9/tree/cmd
Usage

Once imported, you can use the tool to generate tree nodes for your own types. Like so:

import _ "github.com/PlayerR9/tree"

//go:generate go run github.com/PlayerR9/tree/cmd -name=Foo -fields=value/int

This will generate a tree node with the name "Foo" that contains, among other things, the field "value" of type "int."

The type generated will be in the same package as the tool. Make sure to read the documentation of the tool before using it.

Documentation

This command generates a tree node with the given fields that uses first child/next sibling pointers.

To use it, run the following command:

//go:generate go run github.com/PlayerR9/tree/cmd -name=<type_name> -fields=<field_list> [ -g=<generics>] [ -o=<output_file> ]


**Flag: Type Name**

The "type name" flag is used to specify the name of the tree node struct. As such, it must be set and,
not only does it have to be a valid Go identifier, but it also must start with an upper case letter.


**Flag: Fields**

The "fields" flag is used to specify the fields that the tree node contains. Because it doesn't make
a lot of sense to have a tree node without fields, this flag must be set.

Its argument is specified as a list of key-value pairs where each pair is separated by a comma (",") and
a slash ("/") is used to separate the key and the value.

The key indicates the name of the field while the value indicates the type of the field.

For instance, running the following command:

//go:generate go run github.com/PlayerR9/tree/cmd -name=TreeNode -fields=a/int,b/int,name/string

will generate a tree node with the following fields:

type TreeNode struct {
	// Node pointers.

	a int
	b int
	name string
}

It is important to note that spaces are not allowed.

Also, it is possible to specify generics by following the value with the generics between square brackets;
like so: "a/MyType[T,C]"


**Flag: Generics**

This optional flag is used to specify the type(s) of the generics. However, this only applies if at least one
generic type is specified in the fields flag. If none, then this flag is ignored.

As an edge case, if this flag is not specified but the fields flag contains generics, then
all generics are set to the default value of "any".

As with the fields flag, its argument is specified as a list of key-value pairs where each pair is separated
by a comma (",") and a slash ("/") is used to separate the key and the value. The key indicates the name of
the generic and the value indicates the type of the generic.

For instance, running the following command:

//go:generate go run github.com/PlayerR9/tree/cmd -type=TreeNode -fields=a/MyType[T],b/MyType[C] -g=T/any,C/int

will generate a tree node with the following fields:

type TreeNode[T any, C int] struct {
	// Node pointers.

	a T
	b C
}


**Flag: Output File**

This optional flag is used to specify the output file. If not specified, the output will be written to
standard output, that is, the file "<type_name>_treenode.go" in the root of the current directory.

Content

Here are all the pregenerated files:

Documentation

Overview

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Code generated by go generate; EDIT THIS FILE DIRECTLY

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolNode

type BoolNode struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *BoolNode
	Data                                                    bool
}

BoolNode is a node in a tree.

func NewBoolNode

func NewBoolNode(data bool) *BoolNode

NewBoolNode creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *BoolNode: A pointer to the newly created node. It is never nil.

func (*BoolNode) AddChild

func (tn *BoolNode) AddChild(target *BoolNode)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*BoolNode) AddChildren

func (tn *BoolNode) AddChildren(children []*BoolNode)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the BoolNode.AddChild function.

Parameters:

  • children: The children to add.

func (BoolNode) BackwardChild added in v0.1.13

func (tn BoolNode) BackwardChild() iter.Seq[*BoolNode]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*BoolNode]: A sequence of the children of the node.

func (BoolNode) Child added in v0.1.13

func (tn BoolNode) Child() iter.Seq[*BoolNode]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*BoolNode]: A sequence of the children of the node.

func (*BoolNode) Cleanup

func (tn *BoolNode) Cleanup() []*BoolNode

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*BoolNode: The children of the node.

If the receiver is nil, it returns nil.

func (BoolNode) Copy

func (tn BoolNode) Copy() *BoolNode

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*BoolNode) DeleteChild

func (tn *BoolNode) DeleteChild(target *BoolNode) []*BoolNode

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*BoolNode: A slice of the children of the target node.

func (BoolNode) GetChildren

func (tn BoolNode) GetChildren() []*BoolNode

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*BoolNode: A slice of pointers to the children of the node.

func (BoolNode) GetFirstChild

func (tn BoolNode) GetFirstChild() (*BoolNode, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *BoolNode: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (BoolNode) GetParent

func (tn BoolNode) GetParent() (*BoolNode, bool)

GetParent returns the parent of the node.

Returns:

  • *BoolNode: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (BoolNode) HasChild

func (tn BoolNode) HasChild(target *BoolNode) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (BoolNode) IsChildOf

func (tn BoolNode) IsChildOf(target *BoolNode) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (BoolNode) IsLeaf

func (tn BoolNode) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (BoolNode) IsSingleton

func (tn BoolNode) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*BoolNode) LinkChildren

func (tn *BoolNode) LinkChildren(children []*BoolNode)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*BoolNode) RemoveNode

func (tn *BoolNode) RemoveNode() []*BoolNode

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*BoolNode: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (BoolNode) String

func (tn BoolNode) String() string

String implements the tree.Noder interface.

type ByteNode

type ByteNode struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *ByteNode
	Data                                                    byte
}

ByteNode is a node in a tree.

func NewByteNode

func NewByteNode(data byte) *ByteNode

NewByteNode creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *ByteNode: A pointer to the newly created node. It is never nil.

func (*ByteNode) AddChild

func (tn *ByteNode) AddChild(target *ByteNode)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*ByteNode) AddChildren

func (tn *ByteNode) AddChildren(children []*ByteNode)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the ByteNode.AddChild function.

Parameters:

  • children: The children to add.

func (ByteNode) BackwardChild added in v0.1.13

func (tn ByteNode) BackwardChild() iter.Seq[*ByteNode]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*ByteNode]: A sequence of the children of the node.

func (ByteNode) Child added in v0.1.13

func (tn ByteNode) Child() iter.Seq[*ByteNode]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*ByteNode]: A sequence of the children of the node.

func (*ByteNode) Cleanup

func (tn *ByteNode) Cleanup() []*ByteNode

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*ByteNode: The children of the node.

If the receiver is nil, it returns nil.

func (ByteNode) Copy

func (tn ByteNode) Copy() *ByteNode

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*ByteNode) DeleteChild

func (tn *ByteNode) DeleteChild(target *ByteNode) []*ByteNode

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*ByteNode: A slice of the children of the target node.

func (ByteNode) GetChildren

func (tn ByteNode) GetChildren() []*ByteNode

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*ByteNode: A slice of pointers to the children of the node.

func (ByteNode) GetFirstChild

func (tn ByteNode) GetFirstChild() (*ByteNode, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *ByteNode: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (ByteNode) GetParent

func (tn ByteNode) GetParent() (*ByteNode, bool)

GetParent returns the parent of the node.

Returns:

  • *ByteNode: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (ByteNode) HasChild

func (tn ByteNode) HasChild(target *ByteNode) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (ByteNode) IsChildOf

func (tn ByteNode) IsChildOf(target *ByteNode) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (ByteNode) IsLeaf

func (tn ByteNode) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (ByteNode) IsSingleton

func (tn ByteNode) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*ByteNode) LinkChildren

func (tn *ByteNode) LinkChildren(children []*ByteNode)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*ByteNode) RemoveNode

func (tn *ByteNode) RemoveNode() []*ByteNode

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*ByteNode: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (ByteNode) String

func (tn ByteNode) String() string

String implements the tree.Noder interface.

type Complex128Node

type Complex128Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Complex128Node
	Data                                                    complex128
}

Complex128Node is a node in a tree.

func NewComplex128Node

func NewComplex128Node(data complex128) *Complex128Node

NewComplex128Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Complex128Node: A pointer to the newly created node. It is never nil.

func (*Complex128Node) AddChild

func (tn *Complex128Node) AddChild(target *Complex128Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Complex128Node) AddChildren

func (tn *Complex128Node) AddChildren(children []*Complex128Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Complex128Node.AddChild function.

Parameters:

  • children: The children to add.

func (Complex128Node) BackwardChild added in v0.1.13

func (tn Complex128Node) BackwardChild() iter.Seq[*Complex128Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Complex128Node]: A sequence of the children of the node.

func (Complex128Node) Child added in v0.1.13

func (tn Complex128Node) Child() iter.Seq[*Complex128Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Complex128Node]: A sequence of the children of the node.

func (*Complex128Node) Cleanup

func (tn *Complex128Node) Cleanup() []*Complex128Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Complex128Node: The children of the node.

If the receiver is nil, it returns nil.

func (Complex128Node) Copy

func (tn Complex128Node) Copy() *Complex128Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Complex128Node) DeleteChild

func (tn *Complex128Node) DeleteChild(target *Complex128Node) []*Complex128Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Complex128Node: A slice of the children of the target node.

func (Complex128Node) GetChildren

func (tn Complex128Node) GetChildren() []*Complex128Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Complex128Node: A slice of pointers to the children of the node.

func (Complex128Node) GetFirstChild

func (tn Complex128Node) GetFirstChild() (*Complex128Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Complex128Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Complex128Node) GetParent

func (tn Complex128Node) GetParent() (*Complex128Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Complex128Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Complex128Node) HasChild

func (tn Complex128Node) HasChild(target *Complex128Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Complex128Node) IsChildOf

func (tn Complex128Node) IsChildOf(target *Complex128Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Complex128Node) IsLeaf

func (tn Complex128Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Complex128Node) IsSingleton

func (tn Complex128Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Complex128Node) LinkChildren

func (tn *Complex128Node) LinkChildren(children []*Complex128Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Complex128Node) RemoveNode

func (tn *Complex128Node) RemoveNode() []*Complex128Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Complex128Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Complex128Node) String

func (tn Complex128Node) String() string

String implements the tree.Noder interface.

type Complex64Node

type Complex64Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Complex64Node
	Data                                                    complex64
}

Complex64Node is a node in a tree.

func NewComplex64Node

func NewComplex64Node(data complex64) *Complex64Node

NewComplex64Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Complex64Node: A pointer to the newly created node. It is never nil.

func (*Complex64Node) AddChild

func (tn *Complex64Node) AddChild(target *Complex64Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Complex64Node) AddChildren

func (tn *Complex64Node) AddChildren(children []*Complex64Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Complex64Node.AddChild function.

Parameters:

  • children: The children to add.

func (Complex64Node) BackwardChild added in v0.1.13

func (tn Complex64Node) BackwardChild() iter.Seq[*Complex64Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Complex64Node]: A sequence of the children of the node.

func (Complex64Node) Child added in v0.1.13

func (tn Complex64Node) Child() iter.Seq[*Complex64Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Complex64Node]: A sequence of the children of the node.

func (*Complex64Node) Cleanup

func (tn *Complex64Node) Cleanup() []*Complex64Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Complex64Node: The children of the node.

If the receiver is nil, it returns nil.

func (Complex64Node) Copy

func (tn Complex64Node) Copy() *Complex64Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Complex64Node) DeleteChild

func (tn *Complex64Node) DeleteChild(target *Complex64Node) []*Complex64Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Complex64Node: A slice of the children of the target node.

func (Complex64Node) GetChildren

func (tn Complex64Node) GetChildren() []*Complex64Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Complex64Node: A slice of pointers to the children of the node.

func (Complex64Node) GetFirstChild

func (tn Complex64Node) GetFirstChild() (*Complex64Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Complex64Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Complex64Node) GetParent

func (tn Complex64Node) GetParent() (*Complex64Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Complex64Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Complex64Node) HasChild

func (tn Complex64Node) HasChild(target *Complex64Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Complex64Node) IsChildOf

func (tn Complex64Node) IsChildOf(target *Complex64Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Complex64Node) IsLeaf

func (tn Complex64Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Complex64Node) IsSingleton

func (tn Complex64Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Complex64Node) LinkChildren

func (tn *Complex64Node) LinkChildren(children []*Complex64Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Complex64Node) RemoveNode

func (tn *Complex64Node) RemoveNode() []*Complex64Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Complex64Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Complex64Node) String

func (tn Complex64Node) String() string

String implements the tree.Noder interface.

type ErrorNode

type ErrorNode struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *ErrorNode
	Data                                                    error
}

ErrorNode is a node in a tree.

func NewErrorNode

func NewErrorNode(data error) *ErrorNode

NewErrorNode creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *ErrorNode: A pointer to the newly created node. It is never nil.

func (*ErrorNode) AddChild

func (tn *ErrorNode) AddChild(target *ErrorNode)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*ErrorNode) AddChildren

func (tn *ErrorNode) AddChildren(children []*ErrorNode)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the ErrorNode.AddChild function.

Parameters:

  • children: The children to add.

func (ErrorNode) BackwardChild added in v0.1.13

func (tn ErrorNode) BackwardChild() iter.Seq[*ErrorNode]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*ErrorNode]: A sequence of the children of the node.

func (ErrorNode) Child added in v0.1.13

func (tn ErrorNode) Child() iter.Seq[*ErrorNode]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*ErrorNode]: A sequence of the children of the node.

func (*ErrorNode) Cleanup

func (tn *ErrorNode) Cleanup() []*ErrorNode

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*ErrorNode: The children of the node.

If the receiver is nil, it returns nil.

func (ErrorNode) Copy

func (tn ErrorNode) Copy() *ErrorNode

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*ErrorNode) DeleteChild

func (tn *ErrorNode) DeleteChild(target *ErrorNode) []*ErrorNode

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*ErrorNode: A slice of the children of the target node.

func (ErrorNode) GetChildren

func (tn ErrorNode) GetChildren() []*ErrorNode

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*ErrorNode: A slice of pointers to the children of the node.

func (ErrorNode) GetFirstChild

func (tn ErrorNode) GetFirstChild() (*ErrorNode, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *ErrorNode: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (ErrorNode) GetParent

func (tn ErrorNode) GetParent() (*ErrorNode, bool)

GetParent returns the parent of the node.

Returns:

  • *ErrorNode: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (ErrorNode) HasChild

func (tn ErrorNode) HasChild(target *ErrorNode) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (ErrorNode) IsChildOf

func (tn ErrorNode) IsChildOf(target *ErrorNode) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (ErrorNode) IsLeaf

func (tn ErrorNode) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (ErrorNode) IsSingleton

func (tn ErrorNode) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*ErrorNode) LinkChildren

func (tn *ErrorNode) LinkChildren(children []*ErrorNode)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*ErrorNode) RemoveNode

func (tn *ErrorNode) RemoveNode() []*ErrorNode

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*ErrorNode: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (ErrorNode) String

func (tn ErrorNode) String() string

String implements the tree.Noder interface.

type Float32Node

type Float32Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Float32Node
	Data                                                    float32
}

Float32Node is a node in a tree.

func NewFloat32Node

func NewFloat32Node(data float32) *Float32Node

NewFloat32Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Float32Node: A pointer to the newly created node. It is never nil.

func (*Float32Node) AddChild

func (tn *Float32Node) AddChild(target *Float32Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Float32Node) AddChildren

func (tn *Float32Node) AddChildren(children []*Float32Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Float32Node.AddChild function.

Parameters:

  • children: The children to add.

func (Float32Node) BackwardChild added in v0.1.13

func (tn Float32Node) BackwardChild() iter.Seq[*Float32Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Float32Node]: A sequence of the children of the node.

func (Float32Node) Child added in v0.1.13

func (tn Float32Node) Child() iter.Seq[*Float32Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Float32Node]: A sequence of the children of the node.

func (*Float32Node) Cleanup

func (tn *Float32Node) Cleanup() []*Float32Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Float32Node: The children of the node.

If the receiver is nil, it returns nil.

func (Float32Node) Copy

func (tn Float32Node) Copy() *Float32Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Float32Node) DeleteChild

func (tn *Float32Node) DeleteChild(target *Float32Node) []*Float32Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Float32Node: A slice of the children of the target node.

func (Float32Node) GetChildren

func (tn Float32Node) GetChildren() []*Float32Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Float32Node: A slice of pointers to the children of the node.

func (Float32Node) GetFirstChild

func (tn Float32Node) GetFirstChild() (*Float32Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Float32Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Float32Node) GetParent

func (tn Float32Node) GetParent() (*Float32Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Float32Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Float32Node) HasChild

func (tn Float32Node) HasChild(target *Float32Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Float32Node) IsChildOf

func (tn Float32Node) IsChildOf(target *Float32Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Float32Node) IsLeaf

func (tn Float32Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Float32Node) IsSingleton

func (tn Float32Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Float32Node) LinkChildren

func (tn *Float32Node) LinkChildren(children []*Float32Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Float32Node) RemoveNode

func (tn *Float32Node) RemoveNode() []*Float32Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Float32Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Float32Node) String

func (tn Float32Node) String() string

String implements the tree.Noder interface.

type Float64Node

type Float64Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Float64Node
	Data                                                    float64
}

Float64Node is a node in a tree.

func NewFloat64Node

func NewFloat64Node(data float64) *Float64Node

NewFloat64Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Float64Node: A pointer to the newly created node. It is never nil.

func (*Float64Node) AddChild

func (tn *Float64Node) AddChild(target *Float64Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Float64Node) AddChildren

func (tn *Float64Node) AddChildren(children []*Float64Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Float64Node.AddChild function.

Parameters:

  • children: The children to add.

func (Float64Node) BackwardChild added in v0.1.13

func (tn Float64Node) BackwardChild() iter.Seq[*Float64Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Float64Node]: A sequence of the children of the node.

func (Float64Node) Child added in v0.1.13

func (tn Float64Node) Child() iter.Seq[*Float64Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Float64Node]: A sequence of the children of the node.

func (*Float64Node) Cleanup

func (tn *Float64Node) Cleanup() []*Float64Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Float64Node: The children of the node.

If the receiver is nil, it returns nil.

func (Float64Node) Copy

func (tn Float64Node) Copy() *Float64Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Float64Node) DeleteChild

func (tn *Float64Node) DeleteChild(target *Float64Node) []*Float64Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Float64Node: A slice of the children of the target node.

func (Float64Node) GetChildren

func (tn Float64Node) GetChildren() []*Float64Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Float64Node: A slice of pointers to the children of the node.

func (Float64Node) GetFirstChild

func (tn Float64Node) GetFirstChild() (*Float64Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Float64Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Float64Node) GetParent

func (tn Float64Node) GetParent() (*Float64Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Float64Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Float64Node) HasChild

func (tn Float64Node) HasChild(target *Float64Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Float64Node) IsChildOf

func (tn Float64Node) IsChildOf(target *Float64Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Float64Node) IsLeaf

func (tn Float64Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Float64Node) IsSingleton

func (tn Float64Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Float64Node) LinkChildren

func (tn *Float64Node) LinkChildren(children []*Float64Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Float64Node) RemoveNode

func (tn *Float64Node) RemoveNode() []*Float64Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Float64Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Float64Node) String

func (tn Float64Node) String() string

String implements the tree.Noder interface.

type Int16Node

type Int16Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Int16Node
	Data                                                    int16
}

Int16Node is a node in a tree.

func NewInt16Node

func NewInt16Node(data int16) *Int16Node

NewInt16Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Int16Node: A pointer to the newly created node. It is never nil.

func (*Int16Node) AddChild

func (tn *Int16Node) AddChild(target *Int16Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Int16Node) AddChildren

func (tn *Int16Node) AddChildren(children []*Int16Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Int16Node.AddChild function.

Parameters:

  • children: The children to add.

func (Int16Node) BackwardChild added in v0.1.13

func (tn Int16Node) BackwardChild() iter.Seq[*Int16Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Int16Node]: A sequence of the children of the node.

func (Int16Node) Child added in v0.1.13

func (tn Int16Node) Child() iter.Seq[*Int16Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Int16Node]: A sequence of the children of the node.

func (*Int16Node) Cleanup

func (tn *Int16Node) Cleanup() []*Int16Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Int16Node: The children of the node.

If the receiver is nil, it returns nil.

func (Int16Node) Copy

func (tn Int16Node) Copy() *Int16Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Int16Node) DeleteChild

func (tn *Int16Node) DeleteChild(target *Int16Node) []*Int16Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Int16Node: A slice of the children of the target node.

func (Int16Node) GetChildren

func (tn Int16Node) GetChildren() []*Int16Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Int16Node: A slice of pointers to the children of the node.

func (Int16Node) GetFirstChild

func (tn Int16Node) GetFirstChild() (*Int16Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Int16Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Int16Node) GetParent

func (tn Int16Node) GetParent() (*Int16Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Int16Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Int16Node) HasChild

func (tn Int16Node) HasChild(target *Int16Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Int16Node) IsChildOf

func (tn Int16Node) IsChildOf(target *Int16Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Int16Node) IsLeaf

func (tn Int16Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Int16Node) IsSingleton

func (tn Int16Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Int16Node) LinkChildren

func (tn *Int16Node) LinkChildren(children []*Int16Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Int16Node) RemoveNode

func (tn *Int16Node) RemoveNode() []*Int16Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Int16Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Int16Node) String

func (tn Int16Node) String() string

String implements the tree.Noder interface.

type Int32Node

type Int32Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Int32Node
	Data                                                    int32
}

Int32Node is a node in a tree.

func NewInt32Node

func NewInt32Node(data int32) *Int32Node

NewInt32Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Int32Node: A pointer to the newly created node. It is never nil.

func (*Int32Node) AddChild

func (tn *Int32Node) AddChild(target *Int32Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Int32Node) AddChildren

func (tn *Int32Node) AddChildren(children []*Int32Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Int32Node.AddChild function.

Parameters:

  • children: The children to add.

func (Int32Node) BackwardChild added in v0.1.13

func (tn Int32Node) BackwardChild() iter.Seq[*Int32Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Int32Node]: A sequence of the children of the node.

func (Int32Node) Child added in v0.1.13

func (tn Int32Node) Child() iter.Seq[*Int32Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Int32Node]: A sequence of the children of the node.

func (*Int32Node) Cleanup

func (tn *Int32Node) Cleanup() []*Int32Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Int32Node: The children of the node.

If the receiver is nil, it returns nil.

func (Int32Node) Copy

func (tn Int32Node) Copy() *Int32Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Int32Node) DeleteChild

func (tn *Int32Node) DeleteChild(target *Int32Node) []*Int32Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Int32Node: A slice of the children of the target node.

func (Int32Node) GetChildren

func (tn Int32Node) GetChildren() []*Int32Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Int32Node: A slice of pointers to the children of the node.

func (Int32Node) GetFirstChild

func (tn Int32Node) GetFirstChild() (*Int32Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Int32Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Int32Node) GetParent

func (tn Int32Node) GetParent() (*Int32Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Int32Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Int32Node) HasChild

func (tn Int32Node) HasChild(target *Int32Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Int32Node) IsChildOf

func (tn Int32Node) IsChildOf(target *Int32Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Int32Node) IsLeaf

func (tn Int32Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Int32Node) IsSingleton

func (tn Int32Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Int32Node) LinkChildren

func (tn *Int32Node) LinkChildren(children []*Int32Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Int32Node) RemoveNode

func (tn *Int32Node) RemoveNode() []*Int32Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Int32Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Int32Node) String

func (tn Int32Node) String() string

String implements the tree.Noder interface.

type Int64Node

type Int64Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Int64Node
	Data                                                    int64
}

Int64Node is a node in a tree.

func NewInt64Node

func NewInt64Node(data int64) *Int64Node

NewInt64Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Int64Node: A pointer to the newly created node. It is never nil.

func (*Int64Node) AddChild

func (tn *Int64Node) AddChild(target *Int64Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Int64Node) AddChildren

func (tn *Int64Node) AddChildren(children []*Int64Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Int64Node.AddChild function.

Parameters:

  • children: The children to add.

func (Int64Node) BackwardChild added in v0.1.13

func (tn Int64Node) BackwardChild() iter.Seq[*Int64Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Int64Node]: A sequence of the children of the node.

func (Int64Node) Child added in v0.1.13

func (tn Int64Node) Child() iter.Seq[*Int64Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Int64Node]: A sequence of the children of the node.

func (*Int64Node) Cleanup

func (tn *Int64Node) Cleanup() []*Int64Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Int64Node: The children of the node.

If the receiver is nil, it returns nil.

func (Int64Node) Copy

func (tn Int64Node) Copy() *Int64Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Int64Node) DeleteChild

func (tn *Int64Node) DeleteChild(target *Int64Node) []*Int64Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Int64Node: A slice of the children of the target node.

func (Int64Node) GetChildren

func (tn Int64Node) GetChildren() []*Int64Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Int64Node: A slice of pointers to the children of the node.

func (Int64Node) GetFirstChild

func (tn Int64Node) GetFirstChild() (*Int64Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Int64Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Int64Node) GetParent

func (tn Int64Node) GetParent() (*Int64Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Int64Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Int64Node) HasChild

func (tn Int64Node) HasChild(target *Int64Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Int64Node) IsChildOf

func (tn Int64Node) IsChildOf(target *Int64Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Int64Node) IsLeaf

func (tn Int64Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Int64Node) IsSingleton

func (tn Int64Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Int64Node) LinkChildren

func (tn *Int64Node) LinkChildren(children []*Int64Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Int64Node) RemoveNode

func (tn *Int64Node) RemoveNode() []*Int64Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Int64Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Int64Node) String

func (tn Int64Node) String() string

String implements the tree.Noder interface.

type Int8Node

type Int8Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Int8Node
	Data                                                    int8
}

Int8Node is a node in a tree.

func NewInt8Node

func NewInt8Node(data int8) *Int8Node

NewInt8Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Int8Node: A pointer to the newly created node. It is never nil.

func (*Int8Node) AddChild

func (tn *Int8Node) AddChild(target *Int8Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Int8Node) AddChildren

func (tn *Int8Node) AddChildren(children []*Int8Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Int8Node.AddChild function.

Parameters:

  • children: The children to add.

func (Int8Node) BackwardChild added in v0.1.13

func (tn Int8Node) BackwardChild() iter.Seq[*Int8Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Int8Node]: A sequence of the children of the node.

func (Int8Node) Child added in v0.1.13

func (tn Int8Node) Child() iter.Seq[*Int8Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Int8Node]: A sequence of the children of the node.

func (*Int8Node) Cleanup

func (tn *Int8Node) Cleanup() []*Int8Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Int8Node: The children of the node.

If the receiver is nil, it returns nil.

func (Int8Node) Copy

func (tn Int8Node) Copy() *Int8Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Int8Node) DeleteChild

func (tn *Int8Node) DeleteChild(target *Int8Node) []*Int8Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Int8Node: A slice of the children of the target node.

func (Int8Node) GetChildren

func (tn Int8Node) GetChildren() []*Int8Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Int8Node: A slice of pointers to the children of the node.

func (Int8Node) GetFirstChild

func (tn Int8Node) GetFirstChild() (*Int8Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Int8Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Int8Node) GetParent

func (tn Int8Node) GetParent() (*Int8Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Int8Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Int8Node) HasChild

func (tn Int8Node) HasChild(target *Int8Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Int8Node) IsChildOf

func (tn Int8Node) IsChildOf(target *Int8Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Int8Node) IsLeaf

func (tn Int8Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Int8Node) IsSingleton

func (tn Int8Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Int8Node) LinkChildren

func (tn *Int8Node) LinkChildren(children []*Int8Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Int8Node) RemoveNode

func (tn *Int8Node) RemoveNode() []*Int8Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Int8Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Int8Node) String

func (tn Int8Node) String() string

String implements the tree.Noder interface.

type IntNode

type IntNode struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *IntNode
	Data                                                    int
}

IntNode is a node in a tree.

func NewIntNode

func NewIntNode(data int) *IntNode

NewIntNode creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *IntNode: A pointer to the newly created node. It is never nil.

func (*IntNode) AddChild

func (tn *IntNode) AddChild(target *IntNode)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*IntNode) AddChildren

func (tn *IntNode) AddChildren(children []*IntNode)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the IntNode.AddChild function.

Parameters:

  • children: The children to add.

func (IntNode) BackwardChild added in v0.1.13

func (tn IntNode) BackwardChild() iter.Seq[*IntNode]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*IntNode]: A sequence of the children of the node.

func (IntNode) Child added in v0.1.13

func (tn IntNode) Child() iter.Seq[*IntNode]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*IntNode]: A sequence of the children of the node.

func (*IntNode) Cleanup

func (tn *IntNode) Cleanup() []*IntNode

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*IntNode: The children of the node.

If the receiver is nil, it returns nil.

func (IntNode) Copy

func (tn IntNode) Copy() *IntNode

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*IntNode) DeleteChild

func (tn *IntNode) DeleteChild(target *IntNode) []*IntNode

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*IntNode: A slice of the children of the target node.

func (IntNode) GetChildren

func (tn IntNode) GetChildren() []*IntNode

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*IntNode: A slice of pointers to the children of the node.

func (IntNode) GetFirstChild

func (tn IntNode) GetFirstChild() (*IntNode, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *IntNode: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (IntNode) GetParent

func (tn IntNode) GetParent() (*IntNode, bool)

GetParent returns the parent of the node.

Returns:

  • *IntNode: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (IntNode) HasChild

func (tn IntNode) HasChild(target *IntNode) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (IntNode) IsChildOf

func (tn IntNode) IsChildOf(target *IntNode) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (IntNode) IsLeaf

func (tn IntNode) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (IntNode) IsSingleton

func (tn IntNode) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*IntNode) LinkChildren

func (tn *IntNode) LinkChildren(children []*IntNode)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*IntNode) RemoveNode

func (tn *IntNode) RemoveNode() []*IntNode

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*IntNode: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (IntNode) String

func (tn IntNode) String() string

String implements the tree.Noder interface.

type RuneNode

type RuneNode struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *RuneNode
	Data                                                    rune
}

RuneNode is a node in a tree.

func NewRuneNode

func NewRuneNode(data rune) *RuneNode

NewRuneNode creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *RuneNode: A pointer to the newly created node. It is never nil.

func (*RuneNode) AddChild

func (tn *RuneNode) AddChild(target *RuneNode)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*RuneNode) AddChildren

func (tn *RuneNode) AddChildren(children []*RuneNode)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the RuneNode.AddChild function.

Parameters:

  • children: The children to add.

func (RuneNode) BackwardChild added in v0.1.13

func (tn RuneNode) BackwardChild() iter.Seq[*RuneNode]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*RuneNode]: A sequence of the children of the node.

func (RuneNode) Child added in v0.1.13

func (tn RuneNode) Child() iter.Seq[*RuneNode]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*RuneNode]: A sequence of the children of the node.

func (*RuneNode) Cleanup

func (tn *RuneNode) Cleanup() []*RuneNode

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*RuneNode: The children of the node.

If the receiver is nil, it returns nil.

func (RuneNode) Copy

func (tn RuneNode) Copy() *RuneNode

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*RuneNode) DeleteChild

func (tn *RuneNode) DeleteChild(target *RuneNode) []*RuneNode

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*RuneNode: A slice of the children of the target node.

func (RuneNode) GetChildren

func (tn RuneNode) GetChildren() []*RuneNode

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*RuneNode: A slice of pointers to the children of the node.

func (RuneNode) GetFirstChild

func (tn RuneNode) GetFirstChild() (*RuneNode, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *RuneNode: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (RuneNode) GetParent

func (tn RuneNode) GetParent() (*RuneNode, bool)

GetParent returns the parent of the node.

Returns:

  • *RuneNode: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (RuneNode) HasChild

func (tn RuneNode) HasChild(target *RuneNode) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (RuneNode) IsChildOf

func (tn RuneNode) IsChildOf(target *RuneNode) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (RuneNode) IsLeaf

func (tn RuneNode) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (RuneNode) IsSingleton

func (tn RuneNode) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*RuneNode) LinkChildren

func (tn *RuneNode) LinkChildren(children []*RuneNode)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*RuneNode) RemoveNode

func (tn *RuneNode) RemoveNode() []*RuneNode

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*RuneNode: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (RuneNode) String

func (tn RuneNode) String() string

String implements the tree.Noder interface.

type StringNode

type StringNode struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *StringNode
	Data                                                    string
}

StringNode is a node in a tree.

func NewStringNode

func NewStringNode(data string) *StringNode

NewStringNode creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *StringNode: A pointer to the newly created node. It is never nil.

func (*StringNode) AddChild

func (tn *StringNode) AddChild(target *StringNode)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*StringNode) AddChildren

func (tn *StringNode) AddChildren(children []*StringNode)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the StringNode.AddChild function.

Parameters:

  • children: The children to add.

func (StringNode) BackwardChild added in v0.1.13

func (tn StringNode) BackwardChild() iter.Seq[*StringNode]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*StringNode]: A sequence of the children of the node.

func (StringNode) Child added in v0.1.13

func (tn StringNode) Child() iter.Seq[*StringNode]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*StringNode]: A sequence of the children of the node.

func (*StringNode) Cleanup

func (tn *StringNode) Cleanup() []*StringNode

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*StringNode: The children of the node.

If the receiver is nil, it returns nil.

func (StringNode) Copy

func (tn StringNode) Copy() *StringNode

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*StringNode) DeleteChild

func (tn *StringNode) DeleteChild(target *StringNode) []*StringNode

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*StringNode: A slice of the children of the target node.

func (StringNode) GetChildren

func (tn StringNode) GetChildren() []*StringNode

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*StringNode: A slice of pointers to the children of the node.

func (StringNode) GetFirstChild

func (tn StringNode) GetFirstChild() (*StringNode, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *StringNode: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (StringNode) GetParent

func (tn StringNode) GetParent() (*StringNode, bool)

GetParent returns the parent of the node.

Returns:

  • *StringNode: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (StringNode) HasChild

func (tn StringNode) HasChild(target *StringNode) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (StringNode) IsChildOf

func (tn StringNode) IsChildOf(target *StringNode) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (StringNode) IsLeaf

func (tn StringNode) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (StringNode) IsSingleton

func (tn StringNode) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*StringNode) LinkChildren

func (tn *StringNode) LinkChildren(children []*StringNode)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*StringNode) RemoveNode

func (tn *StringNode) RemoveNode() []*StringNode

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*StringNode: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (StringNode) String

func (tn StringNode) String() string

String implements the tree.Noder interface.

type TreeNode

type TreeNode[T any] struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *TreeNode[T]
	Data                                                    T
}

TreeNode is a node in a tree.

func NewTreeNode

func NewTreeNode[T any](data T) *TreeNode[T]

NewTreeNode creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *TreeNode[T]: A pointer to the newly created node. It is never nil.

func (*TreeNode[T]) AddChild

func (tn *TreeNode[T]) AddChild(target *TreeNode[T])

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*TreeNode[T]) AddChildren

func (tn *TreeNode[T]) AddChildren(children []*TreeNode[T])

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the TreeNode.AddChild function.

Parameters:

  • children: The children to add.

func (TreeNode[T]) BackwardChild added in v0.1.13

func (tn TreeNode[T]) BackwardChild() iter.Seq[*TreeNode[T]]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*TreeNode[T]]: A sequence of the children of the node.

func (TreeNode[T]) Child added in v0.1.13

func (tn TreeNode[T]) Child() iter.Seq[*TreeNode[T]]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*TreeNode[T]]: A sequence of the children of the node.

func (*TreeNode[T]) Cleanup

func (tn *TreeNode[T]) Cleanup() []*TreeNode[T]

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*TreeNode[T]: The children of the node.

If the receiver is nil, it returns nil.

func (TreeNode[T]) Copy

func (tn TreeNode[T]) Copy() *TreeNode[T]

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*TreeNode[T]) DeleteChild

func (tn *TreeNode[T]) DeleteChild(target *TreeNode[T]) []*TreeNode[T]

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*TreeNode[T]: A slice of the children of the target node.

func (TreeNode[T]) GetChildren

func (tn TreeNode[T]) GetChildren() []*TreeNode[T]

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*TreeNode[T]: A slice of pointers to the children of the node.

func (TreeNode[T]) GetFirstChild

func (tn TreeNode[T]) GetFirstChild() (*TreeNode[T], bool)

GetFirstChild returns the first child of the node.

Returns:

  • *TreeNode[T]: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (TreeNode[T]) GetParent

func (tn TreeNode[T]) GetParent() (*TreeNode[T], bool)

GetParent returns the parent of the node.

Returns:

  • *TreeNode[T]: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (TreeNode[T]) HasChild

func (tn TreeNode[T]) HasChild(target *TreeNode[T]) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (TreeNode[T]) IsChildOf

func (tn TreeNode[T]) IsChildOf(target *TreeNode[T]) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (TreeNode[T]) IsLeaf

func (tn TreeNode[T]) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (TreeNode[T]) IsSingleton

func (tn TreeNode[T]) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*TreeNode[T]) LinkChildren

func (tn *TreeNode[T]) LinkChildren(children []*TreeNode[T])

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*TreeNode[T]) RemoveNode

func (tn *TreeNode[T]) RemoveNode() []*TreeNode[T]

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*TreeNode[T]: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (TreeNode[T]) String

func (tn TreeNode[T]) String() string

String implements the tree.Noder interface.

type Uint16Node

type Uint16Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Uint16Node
	Data                                                    uint16
}

Uint16Node is a node in a tree.

func NewUint16Node

func NewUint16Node(data uint16) *Uint16Node

NewUint16Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Uint16Node: A pointer to the newly created node. It is never nil.

func (*Uint16Node) AddChild

func (tn *Uint16Node) AddChild(target *Uint16Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Uint16Node) AddChildren

func (tn *Uint16Node) AddChildren(children []*Uint16Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Uint16Node.AddChild function.

Parameters:

  • children: The children to add.

func (Uint16Node) BackwardChild added in v0.1.13

func (tn Uint16Node) BackwardChild() iter.Seq[*Uint16Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Uint16Node]: A sequence of the children of the node.

func (Uint16Node) Child added in v0.1.13

func (tn Uint16Node) Child() iter.Seq[*Uint16Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Uint16Node]: A sequence of the children of the node.

func (*Uint16Node) Cleanup

func (tn *Uint16Node) Cleanup() []*Uint16Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Uint16Node: The children of the node.

If the receiver is nil, it returns nil.

func (Uint16Node) Copy

func (tn Uint16Node) Copy() *Uint16Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Uint16Node) DeleteChild

func (tn *Uint16Node) DeleteChild(target *Uint16Node) []*Uint16Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Uint16Node: A slice of the children of the target node.

func (Uint16Node) GetChildren

func (tn Uint16Node) GetChildren() []*Uint16Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Uint16Node: A slice of pointers to the children of the node.

func (Uint16Node) GetFirstChild

func (tn Uint16Node) GetFirstChild() (*Uint16Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Uint16Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Uint16Node) GetParent

func (tn Uint16Node) GetParent() (*Uint16Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Uint16Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Uint16Node) HasChild

func (tn Uint16Node) HasChild(target *Uint16Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Uint16Node) IsChildOf

func (tn Uint16Node) IsChildOf(target *Uint16Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Uint16Node) IsLeaf

func (tn Uint16Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Uint16Node) IsSingleton

func (tn Uint16Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Uint16Node) LinkChildren

func (tn *Uint16Node) LinkChildren(children []*Uint16Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Uint16Node) RemoveNode

func (tn *Uint16Node) RemoveNode() []*Uint16Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Uint16Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Uint16Node) String

func (tn Uint16Node) String() string

String implements the tree.Noder interface.

type Uint32Node

type Uint32Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Uint32Node
	Data                                                    uint32
}

Uint32Node is a node in a tree.

func NewUint32Node

func NewUint32Node(data uint32) *Uint32Node

NewUint32Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Uint32Node: A pointer to the newly created node. It is never nil.

func (*Uint32Node) AddChild

func (tn *Uint32Node) AddChild(target *Uint32Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Uint32Node) AddChildren

func (tn *Uint32Node) AddChildren(children []*Uint32Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Uint32Node.AddChild function.

Parameters:

  • children: The children to add.

func (Uint32Node) BackwardChild added in v0.1.13

func (tn Uint32Node) BackwardChild() iter.Seq[*Uint32Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Uint32Node]: A sequence of the children of the node.

func (Uint32Node) Child added in v0.1.13

func (tn Uint32Node) Child() iter.Seq[*Uint32Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Uint32Node]: A sequence of the children of the node.

func (*Uint32Node) Cleanup

func (tn *Uint32Node) Cleanup() []*Uint32Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Uint32Node: The children of the node.

If the receiver is nil, it returns nil.

func (Uint32Node) Copy

func (tn Uint32Node) Copy() *Uint32Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Uint32Node) DeleteChild

func (tn *Uint32Node) DeleteChild(target *Uint32Node) []*Uint32Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Uint32Node: A slice of the children of the target node.

func (Uint32Node) GetChildren

func (tn Uint32Node) GetChildren() []*Uint32Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Uint32Node: A slice of pointers to the children of the node.

func (Uint32Node) GetFirstChild

func (tn Uint32Node) GetFirstChild() (*Uint32Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Uint32Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Uint32Node) GetParent

func (tn Uint32Node) GetParent() (*Uint32Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Uint32Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Uint32Node) HasChild

func (tn Uint32Node) HasChild(target *Uint32Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Uint32Node) IsChildOf

func (tn Uint32Node) IsChildOf(target *Uint32Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Uint32Node) IsLeaf

func (tn Uint32Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Uint32Node) IsSingleton

func (tn Uint32Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Uint32Node) LinkChildren

func (tn *Uint32Node) LinkChildren(children []*Uint32Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Uint32Node) RemoveNode

func (tn *Uint32Node) RemoveNode() []*Uint32Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Uint32Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Uint32Node) String

func (tn Uint32Node) String() string

String implements the tree.Noder interface.

type Uint64Node

type Uint64Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Uint64Node
	Data                                                    uint64
}

Uint64Node is a node in a tree.

func NewUint64Node

func NewUint64Node(data uint64) *Uint64Node

NewUint64Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Uint64Node: A pointer to the newly created node. It is never nil.

func (*Uint64Node) AddChild

func (tn *Uint64Node) AddChild(target *Uint64Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Uint64Node) AddChildren

func (tn *Uint64Node) AddChildren(children []*Uint64Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Uint64Node.AddChild function.

Parameters:

  • children: The children to add.

func (Uint64Node) BackwardChild added in v0.1.13

func (tn Uint64Node) BackwardChild() iter.Seq[*Uint64Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Uint64Node]: A sequence of the children of the node.

func (Uint64Node) Child added in v0.1.13

func (tn Uint64Node) Child() iter.Seq[*Uint64Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Uint64Node]: A sequence of the children of the node.

func (*Uint64Node) Cleanup

func (tn *Uint64Node) Cleanup() []*Uint64Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Uint64Node: The children of the node.

If the receiver is nil, it returns nil.

func (Uint64Node) Copy

func (tn Uint64Node) Copy() *Uint64Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Uint64Node) DeleteChild

func (tn *Uint64Node) DeleteChild(target *Uint64Node) []*Uint64Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Uint64Node: A slice of the children of the target node.

func (Uint64Node) GetChildren

func (tn Uint64Node) GetChildren() []*Uint64Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Uint64Node: A slice of pointers to the children of the node.

func (Uint64Node) GetFirstChild

func (tn Uint64Node) GetFirstChild() (*Uint64Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Uint64Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Uint64Node) GetParent

func (tn Uint64Node) GetParent() (*Uint64Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Uint64Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Uint64Node) HasChild

func (tn Uint64Node) HasChild(target *Uint64Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Uint64Node) IsChildOf

func (tn Uint64Node) IsChildOf(target *Uint64Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Uint64Node) IsLeaf

func (tn Uint64Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Uint64Node) IsSingleton

func (tn Uint64Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Uint64Node) LinkChildren

func (tn *Uint64Node) LinkChildren(children []*Uint64Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Uint64Node) RemoveNode

func (tn *Uint64Node) RemoveNode() []*Uint64Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Uint64Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Uint64Node) String

func (tn Uint64Node) String() string

String implements the tree.Noder interface.

type Uint8Node

type Uint8Node struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *Uint8Node
	Data                                                    uint8
}

Uint8Node is a node in a tree.

func NewUint8Node

func NewUint8Node(data uint8) *Uint8Node

NewUint8Node creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *Uint8Node: A pointer to the newly created node. It is never nil.

func (*Uint8Node) AddChild

func (tn *Uint8Node) AddChild(target *Uint8Node)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*Uint8Node) AddChildren

func (tn *Uint8Node) AddChildren(children []*Uint8Node)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the Uint8Node.AddChild function.

Parameters:

  • children: The children to add.

func (Uint8Node) BackwardChild added in v0.1.13

func (tn Uint8Node) BackwardChild() iter.Seq[*Uint8Node]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*Uint8Node]: A sequence of the children of the node.

func (Uint8Node) Child added in v0.1.13

func (tn Uint8Node) Child() iter.Seq[*Uint8Node]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*Uint8Node]: A sequence of the children of the node.

func (*Uint8Node) Cleanup

func (tn *Uint8Node) Cleanup() []*Uint8Node

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*Uint8Node: The children of the node.

If the receiver is nil, it returns nil.

func (Uint8Node) Copy

func (tn Uint8Node) Copy() *Uint8Node

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*Uint8Node) DeleteChild

func (tn *Uint8Node) DeleteChild(target *Uint8Node) []*Uint8Node

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*Uint8Node: A slice of the children of the target node.

func (Uint8Node) GetChildren

func (tn Uint8Node) GetChildren() []*Uint8Node

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*Uint8Node: A slice of pointers to the children of the node.

func (Uint8Node) GetFirstChild

func (tn Uint8Node) GetFirstChild() (*Uint8Node, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *Uint8Node: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (Uint8Node) GetParent

func (tn Uint8Node) GetParent() (*Uint8Node, bool)

GetParent returns the parent of the node.

Returns:

  • *Uint8Node: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (Uint8Node) HasChild

func (tn Uint8Node) HasChild(target *Uint8Node) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (Uint8Node) IsChildOf

func (tn Uint8Node) IsChildOf(target *Uint8Node) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (Uint8Node) IsLeaf

func (tn Uint8Node) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (Uint8Node) IsSingleton

func (tn Uint8Node) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*Uint8Node) LinkChildren

func (tn *Uint8Node) LinkChildren(children []*Uint8Node)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*Uint8Node) RemoveNode

func (tn *Uint8Node) RemoveNode() []*Uint8Node

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*Uint8Node: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (Uint8Node) String

func (tn Uint8Node) String() string

String implements the tree.Noder interface.

type UintNode

type UintNode struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *UintNode
	Data                                                    uint
}

UintNode is a node in a tree.

func NewUintNode

func NewUintNode(data uint) *UintNode

NewUintNode creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *UintNode: A pointer to the newly created node. It is never nil.

func (*UintNode) AddChild

func (tn *UintNode) AddChild(target *UintNode)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*UintNode) AddChildren

func (tn *UintNode) AddChildren(children []*UintNode)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the UintNode.AddChild function.

Parameters:

  • children: The children to add.

func (UintNode) BackwardChild added in v0.1.13

func (tn UintNode) BackwardChild() iter.Seq[*UintNode]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*UintNode]: A sequence of the children of the node.

func (UintNode) Child added in v0.1.13

func (tn UintNode) Child() iter.Seq[*UintNode]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*UintNode]: A sequence of the children of the node.

func (*UintNode) Cleanup

func (tn *UintNode) Cleanup() []*UintNode

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*UintNode: The children of the node.

If the receiver is nil, it returns nil.

func (UintNode) Copy

func (tn UintNode) Copy() *UintNode

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*UintNode) DeleteChild

func (tn *UintNode) DeleteChild(target *UintNode) []*UintNode

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*UintNode: A slice of the children of the target node.

func (UintNode) GetChildren

func (tn UintNode) GetChildren() []*UintNode

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*UintNode: A slice of pointers to the children of the node.

func (UintNode) GetFirstChild

func (tn UintNode) GetFirstChild() (*UintNode, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *UintNode: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (UintNode) GetParent

func (tn UintNode) GetParent() (*UintNode, bool)

GetParent returns the parent of the node.

Returns:

  • *UintNode: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (UintNode) HasChild

func (tn UintNode) HasChild(target *UintNode) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (UintNode) IsChildOf

func (tn UintNode) IsChildOf(target *UintNode) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (UintNode) IsLeaf

func (tn UintNode) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (UintNode) IsSingleton

func (tn UintNode) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*UintNode) LinkChildren

func (tn *UintNode) LinkChildren(children []*UintNode)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*UintNode) RemoveNode

func (tn *UintNode) RemoveNode() []*UintNode

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*UintNode: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (UintNode) String

func (tn UintNode) String() string

String implements the tree.Noder interface.

type UintptrNode

type UintptrNode struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *UintptrNode
	Data                                                    uintptr
}

UintptrNode is a node in a tree.

func NewUintptrNode

func NewUintptrNode(data uintptr) *UintptrNode

NewUintptrNode creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

Returns:

  • *UintptrNode: A pointer to the newly created node. It is never nil.

func (*UintptrNode) AddChild

func (tn *UintptrNode) AddChild(target *UintptrNode)

AddChild adds the target child to the node. Because this function clears the parent and sibling of the target, it does not add its relatives.

Parameters:

  • target: The child to add.

If the receiver or the target are nil, it does nothing.

func (*UintptrNode) AddChildren

func (tn *UintptrNode) AddChildren(children []*UintptrNode)

AddChildren is a convenience function to add multiple children to the node at once. It is more efficient than adding them one by one. Therefore, the behaviors are the same as the behaviors of the UintptrNode.AddChild function.

Parameters:

  • children: The children to add.

func (UintptrNode) BackwardChild added in v0.1.13

func (tn UintptrNode) BackwardChild() iter.Seq[*UintptrNode]

BackwardChild scans the children of the node in reverse order (i.e., from the last child to the first one) and yields them one by one.

Returns:

  • iter.Seq[*UintptrNode]: A sequence of the children of the node.

func (UintptrNode) Child added in v0.1.13

func (tn UintptrNode) Child() iter.Seq[*UintptrNode]

Child scans the children of the node in order (i.e., from the first child to the last one) and yields them one by one.

Returns:

  • iter.Seq[*UintptrNode]: A sequence of the children of the node.

func (*UintptrNode) Cleanup

func (tn *UintptrNode) Cleanup() []*UintptrNode

Cleanup cleans the node and returns its children. This function logically removes the node from the siblings and the parent.

Finally, it is not safe to use in goroutines as pointers may be dereferenced while another goroutine is still using them.

Returns:

  • []*UintptrNode: The children of the node.

If the receiver is nil, it returns nil.

func (UintptrNode) Copy

func (tn UintptrNode) Copy() *UintptrNode

Copy creates a shally copy of the node.

Although this function never returns nil, it does not copy any pointers.

func (*UintptrNode) DeleteChild

func (tn *UintptrNode) DeleteChild(target *UintptrNode) []*UintptrNode

DeleteChild deletes the child from the children of the node while returning the children of the target node.

Parameters:

  • target: The child to remove.

Returns:

  • []*UintptrNode: A slice of the children of the target node.

func (UintptrNode) GetChildren

func (tn UintptrNode) GetChildren() []*UintptrNode

GetChildren returns the immediate children of the node.

The returned nodes are never nil and are not copied. Thus, modifying the returned nodes will modify the tree.

Returns:

  • []*UintptrNode: A slice of pointers to the children of the node.

func (UintptrNode) GetFirstChild

func (tn UintptrNode) GetFirstChild() (*UintptrNode, bool)

GetFirstChild returns the first child of the node.

Returns:

  • *UintptrNode: The first child of the node.
  • bool: True if the node has a child, false otherwise.

func (UintptrNode) GetParent

func (tn UintptrNode) GetParent() (*UintptrNode, bool)

GetParent returns the parent of the node.

Returns:

  • *UintptrNode: The parent of the node.
  • bool: True if the node has a parent, false otherwise.

func (UintptrNode) HasChild

func (tn UintptrNode) HasChild(target *UintptrNode) bool

HasChild returns true if the node has the given child.

Because children of a node cannot be nil, a nil target will always return false.

Parameters:

  • target: The child to check for.

Returns:

  • bool: True if the node has the child, false otherwise.

func (UintptrNode) IsChildOf

func (tn UintptrNode) IsChildOf(target *UintptrNode) bool

IsChildOf returns true if the node is a child of the parent. If target is nil, it returns false.

Parameters:

  • target: The target parent to check for.

Returns:

  • bool: True if the node is a child of the parent, false otherwise.

func (UintptrNode) IsLeaf

func (tn UintptrNode) IsLeaf() bool

IsLeaf implements the tree.Noder interface.

func (UintptrNode) IsSingleton

func (tn UintptrNode) IsSingleton() bool

IsSingleton implements the tree.Noder interface.

func (*UintptrNode) LinkChildren

func (tn *UintptrNode) LinkChildren(children []*UintptrNode)

LinkChildren is a method that links the children of the node.

Parameters:

  • children: The children to link.

Does nothing if the receiver is nil.

func (*UintptrNode) RemoveNode

func (tn *UintptrNode) RemoveNode() []*UintptrNode

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure. The returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []*UintptrNode: A slice of pointers to the children of the node iff the node is the root.

Example:

// Given the tree:
1
├── 2
├── 3
|	├── 4
|	└── 5
└── 6

// The tree after removing node 3:

1
├── 2
├── 4
├── 5
└── 6

func (UintptrNode) String

func (tn UintptrNode) String() string

String implements the tree.Noder interface.

Directories

Path Synopsis
cmd
This command generates a tree node with the given fields that uses first child/next sibling pointers.
This command generates a tree node with the given fields that uses first child/next sibling pointers.

Jump to

Keyboard shortcuts

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