treenode

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: MIT Imports: 5 Imported by: 0

README

treenode

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

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/treenode/cmd/treenode
Usage

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

import _ "github.com/PlayerR9/treenode"

//go:generate go run github.com/PlayerR9/treenode/cmd/treenode -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/treenode -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 treenode -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 treenode -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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolNode added in v0.1.1

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

BoolNode is a node in a tree.

func NewBoolNode added in v0.1.1

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 added in v0.1.1

func (tn *BoolNode) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *BoolNode, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*BoolNode) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *BoolNode) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*BoolNode) Copy added in v0.1.1

func (tn *BoolNode) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*BoolNode) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*BoolNode) GetAncestors added in v0.1.1

func (tn *BoolNode) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*BoolNode) GetChildren added in v0.1.1

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

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:

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

func (*BoolNode) GetFirstChild added in v0.1.1

func (tn *BoolNode) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*BoolNode) GetFirstSibling added in v0.1.1

func (tn *BoolNode) GetFirstSibling() *BoolNode

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *BoolNode: A pointer to the first sibling.

func (*BoolNode) GetLastSibling added in v0.1.1

func (tn *BoolNode) GetLastSibling() *BoolNode

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *BoolNode: A pointer to the last sibling.

func (*BoolNode) GetLeaves added in v0.1.1

func (tn *BoolNode) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*BoolNode) GetParent added in v0.1.1

func (tn *BoolNode) GetParent() Noder

GetParent implements the Noder interface.

func (*BoolNode) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *BoolNode) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*BoolNode) IsRoot added in v0.1.1

func (tn *BoolNode) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*BoolNode) IsSingleton added in v0.1.1

func (tn *BoolNode) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*BoolNode) Iterator added in v0.1.1

func (tn *BoolNode) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*BoolNode) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *BoolNode or nil are ignored.

func (*BoolNode) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*BoolNode) SetParent added in v0.1.1

func (tn *BoolNode) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*BoolNode) Size added in v0.1.1

func (tn *BoolNode) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*BoolNode) String added in v0.1.1

func (tn *BoolNode) String() string

String implements the Noder interface.

type BoolNodeIterator added in v0.1.1

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

BoolNodeIterator is a pull-based iterator that iterates over the children of a BoolNode.

func (*BoolNodeIterator) Consume added in v0.1.1

func (iter *BoolNodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*BoolNodeIterator) Restart added in v0.1.1

func (iter *BoolNodeIterator) Restart()

Restart implements the common.Iterater interface.

type ByteNode added in v0.1.1

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

ByteNode is a node in a tree.

func NewByteNode added in v0.1.1

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 added in v0.1.1

func (tn *ByteNode) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *ByteNode, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*ByteNode) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *ByteNode) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*ByteNode) Copy added in v0.1.1

func (tn *ByteNode) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*ByteNode) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*ByteNode) GetAncestors added in v0.1.1

func (tn *ByteNode) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*ByteNode) GetChildren added in v0.1.1

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

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:

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

func (*ByteNode) GetFirstChild added in v0.1.1

func (tn *ByteNode) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*ByteNode) GetFirstSibling added in v0.1.1

func (tn *ByteNode) GetFirstSibling() *ByteNode

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *ByteNode: A pointer to the first sibling.

func (*ByteNode) GetLastSibling added in v0.1.1

func (tn *ByteNode) GetLastSibling() *ByteNode

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *ByteNode: A pointer to the last sibling.

func (*ByteNode) GetLeaves added in v0.1.1

func (tn *ByteNode) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*ByteNode) GetParent added in v0.1.1

func (tn *ByteNode) GetParent() Noder

GetParent implements the Noder interface.

func (*ByteNode) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *ByteNode) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*ByteNode) IsRoot added in v0.1.1

func (tn *ByteNode) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*ByteNode) IsSingleton added in v0.1.1

func (tn *ByteNode) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*ByteNode) Iterator added in v0.1.1

func (tn *ByteNode) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*ByteNode) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *ByteNode or nil are ignored.

func (*ByteNode) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*ByteNode) SetParent added in v0.1.1

func (tn *ByteNode) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*ByteNode) Size added in v0.1.1

func (tn *ByteNode) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*ByteNode) String added in v0.1.1

func (tn *ByteNode) String() string

String implements the Noder interface.

type ByteNodeIterator added in v0.1.1

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

ByteNodeIterator is a pull-based iterator that iterates over the children of a ByteNode.

func (*ByteNodeIterator) Consume added in v0.1.1

func (iter *ByteNodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*ByteNodeIterator) Restart added in v0.1.1

func (iter *ByteNodeIterator) Restart()

Restart implements the common.Iterater interface.

type Complex128Node added in v0.1.1

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

Complex128Node is a node in a tree.

func NewComplex128Node added in v0.1.1

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 added in v0.1.1

func (tn *Complex128Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Complex128Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Complex128Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Complex128Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Complex128Node) Copy added in v0.1.1

func (tn *Complex128Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Complex128Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Complex128Node) GetAncestors added in v0.1.1

func (tn *Complex128Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Complex128Node) GetChildren added in v0.1.1

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

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:

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

func (*Complex128Node) GetFirstChild added in v0.1.1

func (tn *Complex128Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Complex128Node) GetFirstSibling added in v0.1.1

func (tn *Complex128Node) GetFirstSibling() *Complex128Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Complex128Node: A pointer to the first sibling.

func (*Complex128Node) GetLastSibling added in v0.1.1

func (tn *Complex128Node) GetLastSibling() *Complex128Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Complex128Node: A pointer to the last sibling.

func (*Complex128Node) GetLeaves added in v0.1.1

func (tn *Complex128Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Complex128Node) GetParent added in v0.1.1

func (tn *Complex128Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Complex128Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Complex128Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Complex128Node) IsRoot added in v0.1.1

func (tn *Complex128Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Complex128Node) IsSingleton added in v0.1.1

func (tn *Complex128Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Complex128Node) Iterator added in v0.1.1

func (tn *Complex128Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Complex128Node) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *Complex128Node or nil are ignored.

func (*Complex128Node) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Complex128Node) SetParent added in v0.1.1

func (tn *Complex128Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Complex128Node) Size added in v0.1.1

func (tn *Complex128Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Complex128Node) String added in v0.1.1

func (tn *Complex128Node) String() string

String implements the Noder interface.

type Complex128NodeIterator added in v0.1.1

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

Complex128NodeIterator is a pull-based iterator that iterates over the children of a Complex128Node.

func (*Complex128NodeIterator) Consume added in v0.1.1

func (iter *Complex128NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Complex128NodeIterator) Restart added in v0.1.1

func (iter *Complex128NodeIterator) Restart()

Restart implements the common.Iterater interface.

type Complex64Node added in v0.1.1

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

Complex64Node is a node in a tree.

func NewComplex64Node added in v0.1.1

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 added in v0.1.1

func (tn *Complex64Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Complex64Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Complex64Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Complex64Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Complex64Node) Copy added in v0.1.1

func (tn *Complex64Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Complex64Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Complex64Node) GetAncestors added in v0.1.1

func (tn *Complex64Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Complex64Node) GetChildren added in v0.1.1

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

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:

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

func (*Complex64Node) GetFirstChild added in v0.1.1

func (tn *Complex64Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Complex64Node) GetFirstSibling added in v0.1.1

func (tn *Complex64Node) GetFirstSibling() *Complex64Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Complex64Node: A pointer to the first sibling.

func (*Complex64Node) GetLastSibling added in v0.1.1

func (tn *Complex64Node) GetLastSibling() *Complex64Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Complex64Node: A pointer to the last sibling.

func (*Complex64Node) GetLeaves added in v0.1.1

func (tn *Complex64Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Complex64Node) GetParent added in v0.1.1

func (tn *Complex64Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Complex64Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Complex64Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Complex64Node) IsRoot added in v0.1.1

func (tn *Complex64Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Complex64Node) IsSingleton added in v0.1.1

func (tn *Complex64Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Complex64Node) Iterator added in v0.1.1

func (tn *Complex64Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Complex64Node) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *Complex64Node or nil are ignored.

func (*Complex64Node) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Complex64Node) SetParent added in v0.1.1

func (tn *Complex64Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Complex64Node) Size added in v0.1.1

func (tn *Complex64Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Complex64Node) String added in v0.1.1

func (tn *Complex64Node) String() string

String implements the Noder interface.

type Complex64NodeIterator added in v0.1.1

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

Complex64NodeIterator is a pull-based iterator that iterates over the children of a Complex64Node.

func (*Complex64NodeIterator) Consume added in v0.1.1

func (iter *Complex64NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Complex64NodeIterator) Restart added in v0.1.1

func (iter *Complex64NodeIterator) Restart()

Restart implements the common.Iterater interface.

type ErrorNode added in v0.1.1

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

ErrorNode is a node in a tree.

func NewErrorNode added in v0.1.1

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 added in v0.1.1

func (tn *ErrorNode) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *ErrorNode, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*ErrorNode) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *ErrorNode) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*ErrorNode) Copy added in v0.1.1

func (tn *ErrorNode) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*ErrorNode) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*ErrorNode) GetAncestors added in v0.1.1

func (tn *ErrorNode) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*ErrorNode) GetChildren added in v0.1.1

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

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:

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

func (*ErrorNode) GetFirstChild added in v0.1.1

func (tn *ErrorNode) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*ErrorNode) GetFirstSibling added in v0.1.1

func (tn *ErrorNode) GetFirstSibling() *ErrorNode

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *ErrorNode: A pointer to the first sibling.

func (*ErrorNode) GetLastSibling added in v0.1.1

func (tn *ErrorNode) GetLastSibling() *ErrorNode

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *ErrorNode: A pointer to the last sibling.

func (*ErrorNode) GetLeaves added in v0.1.1

func (tn *ErrorNode) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*ErrorNode) GetParent added in v0.1.1

func (tn *ErrorNode) GetParent() Noder

GetParent implements the Noder interface.

func (*ErrorNode) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *ErrorNode) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*ErrorNode) IsRoot added in v0.1.1

func (tn *ErrorNode) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*ErrorNode) IsSingleton added in v0.1.1

func (tn *ErrorNode) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*ErrorNode) Iterator added in v0.1.1

func (tn *ErrorNode) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*ErrorNode) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *ErrorNode or nil are ignored.

func (*ErrorNode) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*ErrorNode) SetParent added in v0.1.1

func (tn *ErrorNode) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*ErrorNode) Size added in v0.1.1

func (tn *ErrorNode) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*ErrorNode) String added in v0.1.1

func (tn *ErrorNode) String() string

String implements the Noder interface.

type ErrorNodeIterator added in v0.1.1

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

ErrorNodeIterator is a pull-based iterator that iterates over the children of a ErrorNode.

func (*ErrorNodeIterator) Consume added in v0.1.1

func (iter *ErrorNodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*ErrorNodeIterator) Restart added in v0.1.1

func (iter *ErrorNodeIterator) Restart()

Restart implements the common.Iterater interface.

type Float32Node added in v0.1.1

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

Float32Node is a node in a tree.

func NewFloat32Node added in v0.1.1

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 added in v0.1.1

func (tn *Float32Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Float32Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Float32Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Float32Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Float32Node) Copy added in v0.1.1

func (tn *Float32Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Float32Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Float32Node) GetAncestors added in v0.1.1

func (tn *Float32Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Float32Node) GetChildren added in v0.1.1

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

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:

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

func (*Float32Node) GetFirstChild added in v0.1.1

func (tn *Float32Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Float32Node) GetFirstSibling added in v0.1.1

func (tn *Float32Node) GetFirstSibling() *Float32Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Float32Node: A pointer to the first sibling.

func (*Float32Node) GetLastSibling added in v0.1.1

func (tn *Float32Node) GetLastSibling() *Float32Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Float32Node: A pointer to the last sibling.

func (*Float32Node) GetLeaves added in v0.1.1

func (tn *Float32Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Float32Node) GetParent added in v0.1.1

func (tn *Float32Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Float32Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Float32Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Float32Node) IsRoot added in v0.1.1

func (tn *Float32Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Float32Node) IsSingleton added in v0.1.1

func (tn *Float32Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Float32Node) Iterator added in v0.1.1

func (tn *Float32Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Float32Node) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *Float32Node or nil are ignored.

func (*Float32Node) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Float32Node) SetParent added in v0.1.1

func (tn *Float32Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Float32Node) Size added in v0.1.1

func (tn *Float32Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Float32Node) String added in v0.1.1

func (tn *Float32Node) String() string

String implements the Noder interface.

type Float32NodeIterator added in v0.1.1

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

Float32NodeIterator is a pull-based iterator that iterates over the children of a Float32Node.

func (*Float32NodeIterator) Consume added in v0.1.1

func (iter *Float32NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Float32NodeIterator) Restart added in v0.1.1

func (iter *Float32NodeIterator) Restart()

Restart implements the common.Iterater interface.

type Float64Node added in v0.1.1

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

Float64Node is a node in a tree.

func NewFloat64Node added in v0.1.1

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 added in v0.1.1

func (tn *Float64Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Float64Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Float64Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Float64Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Float64Node) Copy added in v0.1.1

func (tn *Float64Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Float64Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Float64Node) GetAncestors added in v0.1.1

func (tn *Float64Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Float64Node) GetChildren added in v0.1.1

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

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:

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

func (*Float64Node) GetFirstChild added in v0.1.1

func (tn *Float64Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Float64Node) GetFirstSibling added in v0.1.1

func (tn *Float64Node) GetFirstSibling() *Float64Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Float64Node: A pointer to the first sibling.

func (*Float64Node) GetLastSibling added in v0.1.1

func (tn *Float64Node) GetLastSibling() *Float64Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Float64Node: A pointer to the last sibling.

func (*Float64Node) GetLeaves added in v0.1.1

func (tn *Float64Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Float64Node) GetParent added in v0.1.1

func (tn *Float64Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Float64Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Float64Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Float64Node) IsRoot added in v0.1.1

func (tn *Float64Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Float64Node) IsSingleton added in v0.1.1

func (tn *Float64Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Float64Node) Iterator added in v0.1.1

func (tn *Float64Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Float64Node) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *Float64Node or nil are ignored.

func (*Float64Node) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Float64Node) SetParent added in v0.1.1

func (tn *Float64Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Float64Node) Size added in v0.1.1

func (tn *Float64Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Float64Node) String added in v0.1.1

func (tn *Float64Node) String() string

String implements the Noder interface.

type Float64NodeIterator added in v0.1.1

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

Float64NodeIterator is a pull-based iterator that iterates over the children of a Float64Node.

func (*Float64NodeIterator) Consume added in v0.1.1

func (iter *Float64NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Float64NodeIterator) Restart added in v0.1.1

func (iter *Float64NodeIterator) Restart()

Restart implements the common.Iterater interface.

type Int16Node added in v0.1.1

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

Int16Node is a node in a tree.

func NewInt16Node added in v0.1.1

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 added in v0.1.1

func (tn *Int16Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Int16Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Int16Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Int16Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Int16Node) Copy added in v0.1.1

func (tn *Int16Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Int16Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Int16Node) GetAncestors added in v0.1.1

func (tn *Int16Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Int16Node) GetChildren added in v0.1.1

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

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:

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

func (*Int16Node) GetFirstChild added in v0.1.1

func (tn *Int16Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Int16Node) GetFirstSibling added in v0.1.1

func (tn *Int16Node) GetFirstSibling() *Int16Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Int16Node: A pointer to the first sibling.

func (*Int16Node) GetLastSibling added in v0.1.1

func (tn *Int16Node) GetLastSibling() *Int16Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Int16Node: A pointer to the last sibling.

func (*Int16Node) GetLeaves added in v0.1.1

func (tn *Int16Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Int16Node) GetParent added in v0.1.1

func (tn *Int16Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Int16Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Int16Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Int16Node) IsRoot added in v0.1.1

func (tn *Int16Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Int16Node) IsSingleton added in v0.1.1

func (tn *Int16Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Int16Node) Iterator added in v0.1.1

func (tn *Int16Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Int16Node) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *Int16Node or nil are ignored.

func (*Int16Node) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Int16Node) SetParent added in v0.1.1

func (tn *Int16Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Int16Node) Size added in v0.1.1

func (tn *Int16Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Int16Node) String added in v0.1.1

func (tn *Int16Node) String() string

String implements the Noder interface.

type Int16NodeIterator added in v0.1.1

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

Int16NodeIterator is a pull-based iterator that iterates over the children of a Int16Node.

func (*Int16NodeIterator) Consume added in v0.1.1

func (iter *Int16NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Int16NodeIterator) Restart added in v0.1.1

func (iter *Int16NodeIterator) Restart()

Restart implements the common.Iterater interface.

type Int32Node added in v0.1.1

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

Int32Node is a node in a tree.

func NewInt32Node added in v0.1.1

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 added in v0.1.1

func (tn *Int32Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Int32Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Int32Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Int32Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Int32Node) Copy added in v0.1.1

func (tn *Int32Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Int32Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Int32Node) GetAncestors added in v0.1.1

func (tn *Int32Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Int32Node) GetChildren added in v0.1.1

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

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:

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

func (*Int32Node) GetFirstChild added in v0.1.1

func (tn *Int32Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Int32Node) GetFirstSibling added in v0.1.1

func (tn *Int32Node) GetFirstSibling() *Int32Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Int32Node: A pointer to the first sibling.

func (*Int32Node) GetLastSibling added in v0.1.1

func (tn *Int32Node) GetLastSibling() *Int32Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Int32Node: A pointer to the last sibling.

func (*Int32Node) GetLeaves added in v0.1.1

func (tn *Int32Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Int32Node) GetParent added in v0.1.1

func (tn *Int32Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Int32Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Int32Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Int32Node) IsRoot added in v0.1.1

func (tn *Int32Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Int32Node) IsSingleton added in v0.1.1

func (tn *Int32Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Int32Node) Iterator added in v0.1.1

func (tn *Int32Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Int32Node) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *Int32Node or nil are ignored.

func (*Int32Node) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Int32Node) SetParent added in v0.1.1

func (tn *Int32Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Int32Node) Size added in v0.1.1

func (tn *Int32Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Int32Node) String added in v0.1.1

func (tn *Int32Node) String() string

String implements the Noder interface.

type Int32NodeIterator added in v0.1.1

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

Int32NodeIterator is a pull-based iterator that iterates over the children of a Int32Node.

func (*Int32NodeIterator) Consume added in v0.1.1

func (iter *Int32NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Int32NodeIterator) Restart added in v0.1.1

func (iter *Int32NodeIterator) Restart()

Restart implements the common.Iterater interface.

type Int64Node added in v0.1.1

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

Int64Node is a node in a tree.

func NewInt64Node added in v0.1.1

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 added in v0.1.1

func (tn *Int64Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Int64Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Int64Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Int64Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Int64Node) Copy added in v0.1.1

func (tn *Int64Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Int64Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Int64Node) GetAncestors added in v0.1.1

func (tn *Int64Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Int64Node) GetChildren added in v0.1.1

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

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:

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

func (*Int64Node) GetFirstChild added in v0.1.1

func (tn *Int64Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Int64Node) GetFirstSibling added in v0.1.1

func (tn *Int64Node) GetFirstSibling() *Int64Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Int64Node: A pointer to the first sibling.

func (*Int64Node) GetLastSibling added in v0.1.1

func (tn *Int64Node) GetLastSibling() *Int64Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Int64Node: A pointer to the last sibling.

func (*Int64Node) GetLeaves added in v0.1.1

func (tn *Int64Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Int64Node) GetParent added in v0.1.1

func (tn *Int64Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Int64Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Int64Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Int64Node) IsRoot added in v0.1.1

func (tn *Int64Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Int64Node) IsSingleton added in v0.1.1

func (tn *Int64Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Int64Node) Iterator added in v0.1.1

func (tn *Int64Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Int64Node) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *Int64Node or nil are ignored.

func (*Int64Node) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Int64Node) SetParent added in v0.1.1

func (tn *Int64Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Int64Node) Size added in v0.1.1

func (tn *Int64Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Int64Node) String added in v0.1.1

func (tn *Int64Node) String() string

String implements the Noder interface.

type Int64NodeIterator added in v0.1.1

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

Int64NodeIterator is a pull-based iterator that iterates over the children of a Int64Node.

func (*Int64NodeIterator) Consume added in v0.1.1

func (iter *Int64NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Int64NodeIterator) Restart added in v0.1.1

func (iter *Int64NodeIterator) Restart()

Restart implements the common.Iterater interface.

type Int8Node added in v0.1.1

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

Int8Node is a node in a tree.

func NewInt8Node added in v0.1.1

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 added in v0.1.1

func (tn *Int8Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Int8Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Int8Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Int8Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Int8Node) Copy added in v0.1.1

func (tn *Int8Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Int8Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Int8Node) GetAncestors added in v0.1.1

func (tn *Int8Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Int8Node) GetChildren added in v0.1.1

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

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:

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

func (*Int8Node) GetFirstChild added in v0.1.1

func (tn *Int8Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Int8Node) GetFirstSibling added in v0.1.1

func (tn *Int8Node) GetFirstSibling() *Int8Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Int8Node: A pointer to the first sibling.

func (*Int8Node) GetLastSibling added in v0.1.1

func (tn *Int8Node) GetLastSibling() *Int8Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Int8Node: A pointer to the last sibling.

func (*Int8Node) GetLeaves added in v0.1.1

func (tn *Int8Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Int8Node) GetParent added in v0.1.1

func (tn *Int8Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Int8Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Int8Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Int8Node) IsRoot added in v0.1.1

func (tn *Int8Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Int8Node) IsSingleton added in v0.1.1

func (tn *Int8Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Int8Node) Iterator added in v0.1.1

func (tn *Int8Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Int8Node) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *Int8Node or nil are ignored.

func (*Int8Node) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Int8Node) SetParent added in v0.1.1

func (tn *Int8Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Int8Node) Size added in v0.1.1

func (tn *Int8Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Int8Node) String added in v0.1.1

func (tn *Int8Node) String() string

String implements the Noder interface.

type Int8NodeIterator added in v0.1.1

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

Int8NodeIterator is a pull-based iterator that iterates over the children of a Int8Node.

func (*Int8NodeIterator) Consume added in v0.1.1

func (iter *Int8NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Int8NodeIterator) Restart added in v0.1.1

func (iter *Int8NodeIterator) Restart()

Restart implements the common.Iterater interface.

type IntNode added in v0.1.1

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

IntNode is a node in a tree.

func NewIntNode added in v0.1.1

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 added in v0.1.1

func (tn *IntNode) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *IntNode, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*IntNode) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *IntNode) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*IntNode) Copy added in v0.1.1

func (tn *IntNode) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*IntNode) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*IntNode) GetAncestors added in v0.1.1

func (tn *IntNode) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*IntNode) GetChildren added in v0.1.1

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

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:

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

func (*IntNode) GetFirstChild added in v0.1.1

func (tn *IntNode) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*IntNode) GetFirstSibling added in v0.1.1

func (tn *IntNode) GetFirstSibling() *IntNode

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *IntNode: A pointer to the first sibling.

func (*IntNode) GetLastSibling added in v0.1.1

func (tn *IntNode) GetLastSibling() *IntNode

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *IntNode: A pointer to the last sibling.

func (*IntNode) GetLeaves added in v0.1.1

func (tn *IntNode) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*IntNode) GetParent added in v0.1.1

func (tn *IntNode) GetParent() Noder

GetParent implements the Noder interface.

func (*IntNode) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *IntNode) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*IntNode) IsRoot added in v0.1.1

func (tn *IntNode) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*IntNode) IsSingleton added in v0.1.1

func (tn *IntNode) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*IntNode) Iterator added in v0.1.1

func (tn *IntNode) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*IntNode) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *IntNode or nil are ignored.

func (*IntNode) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*IntNode) SetParent added in v0.1.1

func (tn *IntNode) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*IntNode) Size added in v0.1.1

func (tn *IntNode) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*IntNode) String added in v0.1.1

func (tn *IntNode) String() string

String implements the Noder interface.

type IntNodeIterator added in v0.1.1

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

IntNodeIterator is a pull-based iterator that iterates over the children of a IntNode.

func (*IntNodeIterator) Consume added in v0.1.1

func (iter *IntNodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*IntNodeIterator) Restart added in v0.1.1

func (iter *IntNodeIterator) Restart()

Restart implements the common.Iterater interface.

type Noder

type Noder interface {
	// SetParent sets the parent of the node.
	//
	// Parameters:
	//   - parent: The parent node.
	//
	// Returns:
	//   - bool: True if the parent is set, false otherwise.
	SetParent(parent Noder) bool

	// GetParent returns the parent of the node.
	//
	// Returns:
	//   - Noder: The parent node.
	GetParent() Noder

	// LinkWithParent links the parent with the children. It also links the children
	// with each other.
	//
	// Parameters:
	//   - parent: The parent node.
	//   - children: The children nodes.
	//
	// Behaviors:
	//   - Only valid children are linked while the rest are ignored.
	LinkChildren(children []Noder)

	// IsLeaf returns true if the node is a leaf.
	//
	// Returns:
	//   - bool: True if the node is a leaf, false otherwise.
	IsLeaf() bool

	// IsSingleton returns true if the node is a singleton (i.e., has only one child).
	//
	// Returns:
	//   - bool: True if the node is a singleton, false otherwise.
	IsSingleton() bool

	// GetLeaves returns all the leaves of the tree rooted at the node.
	//
	// Should be a DFS traversal.
	//
	// Returns:
	//   - []Noder: A slice of pointers to the leaves of the tree.
	//
	// Behaviors:
	//   - The leaves are returned in the order of a DFS traversal.
	GetLeaves() []Noder

	// GetAncestors returns all the ancestors of the node.
	//
	// This excludes the node itself.
	//
	// Returns:
	//   - []Noder: A slice of pointers to the ancestors of the node.
	//
	// Behaviors:
	//   - The ancestors are returned in the opposite order of a DFS traversal.
	//     Therefore, the first element is the parent of the node.
	GetAncestors() []Noder

	// GetFirstChild returns the first child of the node.
	//
	// Returns:
	//   - Noder: The first child of the node. Nil if the node has no children.
	GetFirstChild() Noder

	// DeleteChild removes the given child from the children of the node.
	//
	// Parameters:
	//   - target: The child to remove.
	//
	// Returns:
	//   - []Noder: A slice of pointers to the children of the node. Nil if the node has no children.
	DeleteChild(target Noder) []Noder

	// Size returns the number of nodes in the tree rooted at n.
	//
	// Returns:
	//   - size: The number of nodes in the tree.
	Size() int

	// AddChild adds a new child to the node with the given data.
	//
	// Parameters:
	//   - child: The child to add.
	//
	// Behaviors:
	//   - If the child is not valid, it is ignored.
	AddChild(child Noder)

	// removeNode removes the node from the tree and shifts the children up
	// in the space occupied by the node.
	//
	// Returns:
	//   - []Noder: A slice of pointers to the children of the node if
	//     the node is the root. Nil otherwise.
	RemoveNode() []Noder

	uc.Iterable[Noder]
	uc.Copier
	uto.Cleaner
	fmt.Stringer
}

Noder is an interface that represents a node in a tree.

type RuneNode added in v0.1.1

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

RuneNode is a node in a tree.

func NewRuneNode added in v0.1.1

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 added in v0.1.1

func (tn *RuneNode) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *RuneNode, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*RuneNode) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *RuneNode) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*RuneNode) Copy added in v0.1.1

func (tn *RuneNode) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*RuneNode) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*RuneNode) GetAncestors added in v0.1.1

func (tn *RuneNode) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*RuneNode) GetChildren added in v0.1.1

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

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:

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

func (*RuneNode) GetFirstChild added in v0.1.1

func (tn *RuneNode) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*RuneNode) GetFirstSibling added in v0.1.1

func (tn *RuneNode) GetFirstSibling() *RuneNode

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *RuneNode: A pointer to the first sibling.

func (*RuneNode) GetLastSibling added in v0.1.1

func (tn *RuneNode) GetLastSibling() *RuneNode

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *RuneNode: A pointer to the last sibling.

func (*RuneNode) GetLeaves added in v0.1.1

func (tn *RuneNode) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*RuneNode) GetParent added in v0.1.1

func (tn *RuneNode) GetParent() Noder

GetParent implements the Noder interface.

func (*RuneNode) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *RuneNode) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*RuneNode) IsRoot added in v0.1.1

func (tn *RuneNode) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*RuneNode) IsSingleton added in v0.1.1

func (tn *RuneNode) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*RuneNode) Iterator added in v0.1.1

func (tn *RuneNode) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*RuneNode) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *RuneNode or nil are ignored.

func (*RuneNode) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*RuneNode) SetParent added in v0.1.1

func (tn *RuneNode) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*RuneNode) Size added in v0.1.1

func (tn *RuneNode) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*RuneNode) String added in v0.1.1

func (tn *RuneNode) String() string

String implements the Noder interface.

type RuneNodeIterator added in v0.1.1

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

RuneNodeIterator is a pull-based iterator that iterates over the children of a RuneNode.

func (*RuneNodeIterator) Consume added in v0.1.1

func (iter *RuneNodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*RuneNodeIterator) Restart added in v0.1.1

func (iter *RuneNodeIterator) Restart()

Restart implements the common.Iterater interface.

type StatusNode

type StatusNode[S common.Enumer, T any] struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *StatusNode[S, T]
	Data                                                    T
	Status                                                  S
}

StatusNode is a node in a tree.

func NewStatusNode

func NewStatusNode[S common.Enumer, T any](data T, status S) *StatusNode[S, T]

NewStatusNode creates a new node with the given data.

Parameters:

  • Data: The Data of the node.

  • Status: The Status of the node.

Returns:

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

func (*StatusNode[S, T]) AddChild

func (tn *StatusNode[S, T]) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *StatusNode[S, T], it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*StatusNode[S, T]) AddChildren

func (tn *StatusNode[S, T]) AddChildren(children []*StatusNode[S, 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 StatusNode.AddChild function.

Parameters:

  • children: The children to add.

func (*StatusNode[S, T]) Cleanup

func (tn *StatusNode[S, T]) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*StatusNode[S, T]) Copy

func (tn *StatusNode[S, T]) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*StatusNode[S, T]) DeleteChild

func (tn *StatusNode[S, T]) DeleteChild(target Noder) []Noder

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*StatusNode[S, T]) GetAncestors

func (tn *StatusNode[S, T]) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*StatusNode[S, T]) GetChildren

func (tn *StatusNode[S, T]) GetChildren() []Noder

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:

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

func (*StatusNode[S, T]) GetFirstChild

func (tn *StatusNode[S, T]) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*StatusNode[S, T]) GetFirstSibling

func (tn *StatusNode[S, T]) GetFirstSibling() *StatusNode[S, T]

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *StatusNode[S, T]: A pointer to the first sibling.

func (*StatusNode[S, T]) GetLastSibling

func (tn *StatusNode[S, T]) GetLastSibling() *StatusNode[S, T]

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *StatusNode[S, T]: A pointer to the last sibling.

func (*StatusNode[S, T]) GetLeaves

func (tn *StatusNode[S, T]) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*StatusNode[S, T]) GetParent

func (tn *StatusNode[S, T]) GetParent() Noder

GetParent implements the Noder interface.

func (*StatusNode[S, T]) HasChild

func (tn *StatusNode[S, T]) HasChild(target *StatusNode[S, 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 (*StatusNode[S, T]) IsChildOf

func (tn *StatusNode[S, T]) IsChildOf(target *StatusNode[S, 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 (*StatusNode[S, T]) IsLeaf

func (tn *StatusNode[S, T]) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*StatusNode[S, T]) IsRoot

func (tn *StatusNode[S, T]) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*StatusNode[S, T]) IsSingleton

func (tn *StatusNode[S, T]) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*StatusNode[S, T]) Iterator

func (tn *StatusNode[S, T]) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*StatusNode[S, T]) LinkChildren

func (tn *StatusNode[S, T]) LinkChildren(children []Noder)

LinkWithParent implements the Noder interface.

Children that are not of type *StatusNode[S, T] or nil are ignored.

func (*StatusNode[S, T]) RemoveNode

func (tn *StatusNode[S, T]) RemoveNode() []Noder

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*StatusNode[S, T]) SetParent

func (tn *StatusNode[S, T]) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*StatusNode[S, T]) Size

func (tn *StatusNode[S, T]) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*StatusNode[S, T]) String

func (tn *StatusNode[S, T]) String() string

String implements the Noder interface.

type StatusNodeIterator

type StatusNodeIterator[S common.Enumer, T any] struct {
	// contains filtered or unexported fields
}

StatusNodeIterator is a pull-based iterator that iterates over the children of a StatusNode.

func (*StatusNodeIterator[S, T]) Consume

func (iter *StatusNodeIterator[S, T]) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*StatusNodeIterator[S, T]) Restart

func (iter *StatusNodeIterator[S, T]) Restart()

Restart implements the common.Iterater interface.

type StringNode added in v0.1.1

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

StringNode is a node in a tree.

func NewStringNode added in v0.1.1

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 added in v0.1.1

func (tn *StringNode) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *StringNode, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*StringNode) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *StringNode) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*StringNode) Copy added in v0.1.1

func (tn *StringNode) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*StringNode) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*StringNode) GetAncestors added in v0.1.1

func (tn *StringNode) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*StringNode) GetChildren added in v0.1.1

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

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:

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

func (*StringNode) GetFirstChild added in v0.1.1

func (tn *StringNode) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*StringNode) GetFirstSibling added in v0.1.1

func (tn *StringNode) GetFirstSibling() *StringNode

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *StringNode: A pointer to the first sibling.

func (*StringNode) GetLastSibling added in v0.1.1

func (tn *StringNode) GetLastSibling() *StringNode

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *StringNode: A pointer to the last sibling.

func (*StringNode) GetLeaves added in v0.1.1

func (tn *StringNode) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*StringNode) GetParent added in v0.1.1

func (tn *StringNode) GetParent() Noder

GetParent implements the Noder interface.

func (*StringNode) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *StringNode) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*StringNode) IsRoot added in v0.1.1

func (tn *StringNode) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*StringNode) IsSingleton added in v0.1.1

func (tn *StringNode) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*StringNode) Iterator added in v0.1.1

func (tn *StringNode) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*StringNode) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *StringNode or nil are ignored.

func (*StringNode) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*StringNode) SetParent added in v0.1.1

func (tn *StringNode) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*StringNode) Size added in v0.1.1

func (tn *StringNode) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*StringNode) String added in v0.1.1

func (tn *StringNode) String() string

String implements the Noder interface.

type StringNodeIterator added in v0.1.1

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

StringNodeIterator is a pull-based iterator that iterates over the children of a StringNode.

func (*StringNodeIterator) Consume added in v0.1.1

func (iter *StringNodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*StringNodeIterator) Restart added in v0.1.1

func (iter *StringNodeIterator) Restart()

Restart implements the common.Iterater 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(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *TreeNode[T], it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

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]) Cleanup

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

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*TreeNode[T]) Copy

func (tn *TreeNode[T]) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*TreeNode[T]) DeleteChild

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*TreeNode[T]) GetAncestors

func (tn *TreeNode[T]) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*TreeNode[T]) GetChildren

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

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:

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

func (*TreeNode[T]) GetFirstChild

func (tn *TreeNode[T]) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*TreeNode[T]) GetFirstSibling

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

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *TreeNode[T]: A pointer to the first sibling.

func (*TreeNode[T]) GetLastSibling

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

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *TreeNode[T]: A pointer to the last sibling.

func (*TreeNode[T]) GetLeaves

func (tn *TreeNode[T]) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*TreeNode[T]) GetParent

func (tn *TreeNode[T]) GetParent() Noder

GetParent implements the Noder interface.

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 Noder interface.

func (*TreeNode[T]) IsRoot

func (tn *TreeNode[T]) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*TreeNode[T]) IsSingleton

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

IsSingleton implements the Noder interface.

func (*TreeNode[T]) Iterator

func (tn *TreeNode[T]) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*TreeNode[T]) LinkChildren

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

LinkWithParent implements the Noder interface.

Children that are not of type *TreeNode[T] or nil are ignored.

func (*TreeNode[T]) RemoveNode

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*TreeNode[T]) SetParent

func (tn *TreeNode[T]) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*TreeNode[T]) Size

func (tn *TreeNode[T]) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*TreeNode[T]) String

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

String implements the Noder interface.

type TreeNodeIterator

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

TreeNodeIterator is a pull-based iterator that iterates over the children of a TreeNode.

func (*TreeNodeIterator[T]) Consume

func (iter *TreeNodeIterator[T]) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*TreeNodeIterator[T]) Restart

func (iter *TreeNodeIterator[T]) Restart()

Restart implements the common.Iterater interface.

type Uint16Node added in v0.1.1

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

Uint16Node is a node in a tree.

func NewUint16Node added in v0.1.1

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 added in v0.1.1

func (tn *Uint16Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Uint16Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Uint16Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Uint16Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Uint16Node) Copy added in v0.1.1

func (tn *Uint16Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Uint16Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Uint16Node) GetAncestors added in v0.1.1

func (tn *Uint16Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Uint16Node) GetChildren added in v0.1.1

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

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:

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

func (*Uint16Node) GetFirstChild added in v0.1.1

func (tn *Uint16Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Uint16Node) GetFirstSibling added in v0.1.1

func (tn *Uint16Node) GetFirstSibling() *Uint16Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Uint16Node: A pointer to the first sibling.

func (*Uint16Node) GetLastSibling added in v0.1.1

func (tn *Uint16Node) GetLastSibling() *Uint16Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Uint16Node: A pointer to the last sibling.

func (*Uint16Node) GetLeaves added in v0.1.1

func (tn *Uint16Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Uint16Node) GetParent added in v0.1.1

func (tn *Uint16Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Uint16Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Uint16Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Uint16Node) IsRoot added in v0.1.1

func (tn *Uint16Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Uint16Node) IsSingleton added in v0.1.1

func (tn *Uint16Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Uint16Node) Iterator added in v0.1.1

func (tn *Uint16Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Uint16Node) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *Uint16Node or nil are ignored.

func (*Uint16Node) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Uint16Node) SetParent added in v0.1.1

func (tn *Uint16Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Uint16Node) Size added in v0.1.1

func (tn *Uint16Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Uint16Node) String added in v0.1.1

func (tn *Uint16Node) String() string

String implements the Noder interface.

type Uint16NodeIterator added in v0.1.1

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

Uint16NodeIterator is a pull-based iterator that iterates over the children of a Uint16Node.

func (*Uint16NodeIterator) Consume added in v0.1.1

func (iter *Uint16NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Uint16NodeIterator) Restart added in v0.1.1

func (iter *Uint16NodeIterator) Restart()

Restart implements the common.Iterater interface.

type Uint32Node added in v0.1.1

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

Uint32Node is a node in a tree.

func NewUint32Node added in v0.1.1

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 added in v0.1.1

func (tn *Uint32Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Uint32Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Uint32Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Uint32Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Uint32Node) Copy added in v0.1.1

func (tn *Uint32Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Uint32Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Uint32Node) GetAncestors added in v0.1.1

func (tn *Uint32Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Uint32Node) GetChildren added in v0.1.1

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

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:

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

func (*Uint32Node) GetFirstChild added in v0.1.1

func (tn *Uint32Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Uint32Node) GetFirstSibling added in v0.1.1

func (tn *Uint32Node) GetFirstSibling() *Uint32Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Uint32Node: A pointer to the first sibling.

func (*Uint32Node) GetLastSibling added in v0.1.1

func (tn *Uint32Node) GetLastSibling() *Uint32Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Uint32Node: A pointer to the last sibling.

func (*Uint32Node) GetLeaves added in v0.1.1

func (tn *Uint32Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Uint32Node) GetParent added in v0.1.1

func (tn *Uint32Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Uint32Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Uint32Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Uint32Node) IsRoot added in v0.1.1

func (tn *Uint32Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Uint32Node) IsSingleton added in v0.1.1

func (tn *Uint32Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Uint32Node) Iterator added in v0.1.1

func (tn *Uint32Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Uint32Node) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *Uint32Node or nil are ignored.

func (*Uint32Node) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Uint32Node) SetParent added in v0.1.1

func (tn *Uint32Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Uint32Node) Size added in v0.1.1

func (tn *Uint32Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Uint32Node) String added in v0.1.1

func (tn *Uint32Node) String() string

String implements the Noder interface.

type Uint32NodeIterator added in v0.1.1

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

Uint32NodeIterator is a pull-based iterator that iterates over the children of a Uint32Node.

func (*Uint32NodeIterator) Consume added in v0.1.1

func (iter *Uint32NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Uint32NodeIterator) Restart added in v0.1.1

func (iter *Uint32NodeIterator) Restart()

Restart implements the common.Iterater interface.

type Uint64Node added in v0.1.1

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

Uint64Node is a node in a tree.

func NewUint64Node added in v0.1.1

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 added in v0.1.1

func (tn *Uint64Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Uint64Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Uint64Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Uint64Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Uint64Node) Copy added in v0.1.1

func (tn *Uint64Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Uint64Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Uint64Node) GetAncestors added in v0.1.1

func (tn *Uint64Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Uint64Node) GetChildren added in v0.1.1

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

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:

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

func (*Uint64Node) GetFirstChild added in v0.1.1

func (tn *Uint64Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Uint64Node) GetFirstSibling added in v0.1.1

func (tn *Uint64Node) GetFirstSibling() *Uint64Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Uint64Node: A pointer to the first sibling.

func (*Uint64Node) GetLastSibling added in v0.1.1

func (tn *Uint64Node) GetLastSibling() *Uint64Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Uint64Node: A pointer to the last sibling.

func (*Uint64Node) GetLeaves added in v0.1.1

func (tn *Uint64Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Uint64Node) GetParent added in v0.1.1

func (tn *Uint64Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Uint64Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Uint64Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Uint64Node) IsRoot added in v0.1.1

func (tn *Uint64Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Uint64Node) IsSingleton added in v0.1.1

func (tn *Uint64Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Uint64Node) Iterator added in v0.1.1

func (tn *Uint64Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Uint64Node) LinkChildren added in v0.1.1

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

LinkWithParent implements the Noder interface.

Children that are not of type *Uint64Node or nil are ignored.

func (*Uint64Node) RemoveNode added in v0.1.1

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

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Uint64Node) SetParent added in v0.1.1

func (tn *Uint64Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Uint64Node) Size added in v0.1.1

func (tn *Uint64Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Uint64Node) String added in v0.1.1

func (tn *Uint64Node) String() string

String implements the Noder interface.

type Uint64NodeIterator added in v0.1.1

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

Uint64NodeIterator is a pull-based iterator that iterates over the children of a Uint64Node.

func (*Uint64NodeIterator) Consume added in v0.1.1

func (iter *Uint64NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Uint64NodeIterator) Restart added in v0.1.1

func (iter *Uint64NodeIterator) Restart()

Restart implements the common.Iterater interface.

type Uint8Node added in v0.1.1

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

Uint8Node is a node in a tree.

func NewUint8Node added in v0.1.1

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 added in v0.1.1

func (tn *Uint8Node) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *Uint8Node, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*Uint8Node) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *Uint8Node) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*Uint8Node) Copy added in v0.1.1

func (tn *Uint8Node) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*Uint8Node) DeleteChild added in v0.1.1

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

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*Uint8Node) GetAncestors added in v0.1.1

func (tn *Uint8Node) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Uint8Node) GetChildren added in v0.1.1

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

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:

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

func (*Uint8Node) GetFirstChild added in v0.1.1

func (tn *Uint8Node) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*Uint8Node) GetFirstSibling added in v0.1.1

func (tn *Uint8Node) GetFirstSibling() *Uint8Node

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Uint8Node: A pointer to the first sibling.

func (*Uint8Node) GetLastSibling added in v0.1.1

func (tn *Uint8Node) GetLastSibling() *Uint8Node

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *Uint8Node: A pointer to the last sibling.

func (*Uint8Node) GetLeaves added in v0.1.1

func (tn *Uint8Node) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*Uint8Node) GetParent added in v0.1.1

func (tn *Uint8Node) GetParent() Noder

GetParent implements the Noder interface.

func (*Uint8Node) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *Uint8Node) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*Uint8Node) IsRoot added in v0.1.1

func (tn *Uint8Node) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*Uint8Node) IsSingleton added in v0.1.1

func (tn *Uint8Node) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*Uint8Node) Iterator added in v0.1.1

func (tn *Uint8Node) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*Uint8Node) LinkChildren added in v0.1.1

func (tn *Uint8Node) LinkChildren(children []Noder)

LinkWithParent implements the Noder interface.

Children that are not of type *Uint8Node or nil are ignored.

func (*Uint8Node) RemoveNode added in v0.1.1

func (tn *Uint8Node) RemoveNode() []Noder

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*Uint8Node) SetParent added in v0.1.1

func (tn *Uint8Node) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*Uint8Node) Size added in v0.1.1

func (tn *Uint8Node) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*Uint8Node) String added in v0.1.1

func (tn *Uint8Node) String() string

String implements the Noder interface.

type Uint8NodeIterator added in v0.1.1

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

Uint8NodeIterator is a pull-based iterator that iterates over the children of a Uint8Node.

func (*Uint8NodeIterator) Consume added in v0.1.1

func (iter *Uint8NodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*Uint8NodeIterator) Restart added in v0.1.1

func (iter *Uint8NodeIterator) Restart()

Restart implements the common.Iterater interface.

type UintNode added in v0.1.1

type UintNode struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *UintNode
	Data                                                    uint
}

UintNode is a node in a tree.

func NewUintNode added in v0.1.1

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 added in v0.1.1

func (tn *UintNode) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *UintNode, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*UintNode) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *UintNode) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*UintNode) Copy added in v0.1.1

func (tn *UintNode) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*UintNode) DeleteChild added in v0.1.1

func (tn *UintNode) DeleteChild(target Noder) []Noder

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*UintNode) GetAncestors added in v0.1.1

func (tn *UintNode) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*UintNode) GetChildren added in v0.1.1

func (tn *UintNode) GetChildren() []Noder

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:

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

func (*UintNode) GetFirstChild added in v0.1.1

func (tn *UintNode) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*UintNode) GetFirstSibling added in v0.1.1

func (tn *UintNode) GetFirstSibling() *UintNode

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *UintNode: A pointer to the first sibling.

func (*UintNode) GetLastSibling added in v0.1.1

func (tn *UintNode) GetLastSibling() *UintNode

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *UintNode: A pointer to the last sibling.

func (*UintNode) GetLeaves added in v0.1.1

func (tn *UintNode) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*UintNode) GetParent added in v0.1.1

func (tn *UintNode) GetParent() Noder

GetParent implements the Noder interface.

func (*UintNode) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *UintNode) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*UintNode) IsRoot added in v0.1.1

func (tn *UintNode) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*UintNode) IsSingleton added in v0.1.1

func (tn *UintNode) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*UintNode) Iterator added in v0.1.1

func (tn *UintNode) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*UintNode) LinkChildren added in v0.1.1

func (tn *UintNode) LinkChildren(children []Noder)

LinkWithParent implements the Noder interface.

Children that are not of type *UintNode or nil are ignored.

func (*UintNode) RemoveNode added in v0.1.1

func (tn *UintNode) RemoveNode() []Noder

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*UintNode) SetParent added in v0.1.1

func (tn *UintNode) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*UintNode) Size added in v0.1.1

func (tn *UintNode) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*UintNode) String added in v0.1.1

func (tn *UintNode) String() string

String implements the Noder interface.

type UintNodeIterator added in v0.1.1

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

UintNodeIterator is a pull-based iterator that iterates over the children of a UintNode.

func (*UintNodeIterator) Consume added in v0.1.1

func (iter *UintNodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*UintNodeIterator) Restart added in v0.1.1

func (iter *UintNodeIterator) Restart()

Restart implements the common.Iterater interface.

type UintptrNode added in v0.1.1

type UintptrNode struct {
	Parent, FirstChild, NextSibling, LastChild, PrevSibling *UintptrNode
	Data                                                    uintptr
}

UintptrNode is a node in a tree.

func NewUintptrNode added in v0.1.1

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 added in v0.1.1

func (tn *UintptrNode) AddChild(child Noder)

AddChild adds a new child to the node. If the child is nil or it is not of type *UintptrNode, it does nothing.

This function clears the parent and sibling pointers of the child and so, it does not add relatives to the child.

Parameters:

  • child: The child to add.

func (*UintptrNode) AddChildren added in v0.1.1

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) Cleanup added in v0.1.1

func (tn *UintptrNode) Cleanup()

Cleanup implements the Noder interface.

This is expensive as it has to traverse the whole tree to clean up the nodes, one by one. While this is useful for freeing up memory, for large enough trees, it is recommended to let the garbage collector handle the cleanup.

Despite the above, this function does not use recursion and is safe to use (but make sure goroutines are not running on the tree while this function is called).

Finally, it also logically removes the node from the siblings and the parent.

func (*UintptrNode) Copy added in v0.1.1

func (tn *UintptrNode) Copy() common.Copier

Copy implements the Noder interface.

It never returns nil and it does not copy the parent or the sibling pointers.

func (*UintptrNode) DeleteChild added in v0.1.1

func (tn *UintptrNode) DeleteChild(target Noder) []Noder

DeleteChild implements the Noder interface.

No nil nodes are returned.

func (*UintptrNode) GetAncestors added in v0.1.1

func (tn *UintptrNode) GetAncestors() []Noder

GetAncestors implements the Noder interface.

This is expensive since ancestors are not stored and so, every time this function is called, it has to traverse the tree to find the ancestors. Thus, it is recommended to call this function once and then store the ancestors somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*UintptrNode) GetChildren added in v0.1.1

func (tn *UintptrNode) GetChildren() []Noder

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:

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

func (*UintptrNode) GetFirstChild added in v0.1.1

func (tn *UintptrNode) GetFirstChild() Noder

GetFirstChild implements the Noder interface.

func (*UintptrNode) GetFirstSibling added in v0.1.1

func (tn *UintptrNode) GetFirstSibling() *UintptrNode

GetFirstSibling returns the first sibling of the node. If it has a parent, it returns the first child of the parent. Otherwise, it returns the first sibling of the node.

As an edge case, if the node has no parent and no previous sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *UintptrNode: A pointer to the first sibling.

func (*UintptrNode) GetLastSibling added in v0.1.1

func (tn *UintptrNode) GetLastSibling() *UintptrNode

GetLastSibling returns the last sibling of the node. If it has a parent, it returns the last child of the parent. Otherwise, it returns the last sibling of the node.

As an edge case, if the node has no parent and no next sibling, it returns the node itself. Thus, this function never returns nil.

Returns:

  • *UintptrNode: A pointer to the last sibling.

func (*UintptrNode) GetLeaves added in v0.1.1

func (tn *UintptrNode) GetLeaves() []Noder

GetLeaves implements the Noder interface.

This is expensive as leaves are not stored and so, every time this function is called, it has to do a DFS traversal to find the leaves. Thus, it is recommended to call this function once and then store the leaves somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, no nil nodes are returned.

func (*UintptrNode) GetParent added in v0.1.1

func (tn *UintptrNode) GetParent() Noder

GetParent implements the Noder interface.

func (*UintptrNode) HasChild added in v0.1.1

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 added in v0.1.1

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 added in v0.1.1

func (tn *UintptrNode) IsLeaf() bool

IsLeaf implements the Noder interface.

func (*UintptrNode) IsRoot added in v0.1.1

func (tn *UintptrNode) IsRoot() bool

IsRoot returns true if the node does not have a parent.

Returns:

  • bool: True if the node is the root, false otherwise.

func (*UintptrNode) IsSingleton added in v0.1.1

func (tn *UintptrNode) IsSingleton() bool

IsSingleton implements the Noder interface.

func (*UintptrNode) Iterator added in v0.1.1

func (tn *UintptrNode) Iterator() common.Iterater[Noder]

Iterator implements the Noder interface.

This function iterates over the children of the node, it is a pull-based iterator, and never returns nil.

func (*UintptrNode) LinkChildren added in v0.1.1

func (tn *UintptrNode) LinkChildren(children []Noder)

LinkWithParent implements the Noder interface.

Children that are not of type *UintptrNode or nil are ignored.

func (*UintptrNode) RemoveNode added in v0.1.1

func (tn *UintptrNode) RemoveNode() []Noder

RemoveNode removes the node from the tree while shifting the children up one level to maintain the tree structure.

Also, the returned children can be used to create a forest of trees if the root node is removed.

Returns:

  • []Noder: A slice of pointers to the children of the node iff the node is the root. Nil otherwise.

Example:

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

// The tree after removing node 3:

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

func (*UintptrNode) SetParent added in v0.1.1

func (tn *UintptrNode) SetParent(parent Noder) bool

SetParent implements the Noder interface.

func (*UintptrNode) Size added in v0.1.1

func (tn *UintptrNode) Size() int

Size implements the Noder interface.

This is expensive as it has to traverse the whole tree to find the size of the tree. Thus, it is recommended to call this function once and then store the size somewhere if needed.

Despite the above, this function does not use recursion and is safe to use.

Finally, the traversal is done in a depth-first manner.

func (*UintptrNode) String added in v0.1.1

func (tn *UintptrNode) String() string

String implements the Noder interface.

type UintptrNodeIterator added in v0.1.1

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

UintptrNodeIterator is a pull-based iterator that iterates over the children of a UintptrNode.

func (*UintptrNodeIterator) Consume added in v0.1.1

func (iter *UintptrNodeIterator) Consume() (Noder, error)

Consume implements the common.Iterater interface.

*common.ErrExhaustedIter is the only error returned by this function and the returned node is never nil.

func (*UintptrNodeIterator) Restart added in v0.1.1

func (iter *UintptrNodeIterator) Restart()

Restart implements the common.Iterater interface.

Directories

Path Synopsis
cmd
treenode
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