Documentation ¶
Index ¶
- type BoolNode
- func (tn *BoolNode) AddChild(child Noder)
- func (tn *BoolNode) AddChildren(children []*BoolNode)
- func (tn *BoolNode) Cleanup()
- func (tn *BoolNode) Copy() common.Copier
- func (tn *BoolNode) DeleteChild(target Noder) []Noder
- func (tn *BoolNode) GetAncestors() []Noder
- func (tn *BoolNode) GetChildren() []Noder
- func (tn *BoolNode) GetFirstChild() Noder
- func (tn *BoolNode) GetFirstSibling() *BoolNode
- func (tn *BoolNode) GetLastSibling() *BoolNode
- func (tn *BoolNode) GetLeaves() []Noder
- func (tn *BoolNode) GetParent() Noder
- func (tn *BoolNode) HasChild(target *BoolNode) bool
- func (tn *BoolNode) IsChildOf(target *BoolNode) bool
- func (tn *BoolNode) IsLeaf() bool
- func (tn *BoolNode) IsRoot() bool
- func (tn *BoolNode) IsSingleton() bool
- func (tn *BoolNode) Iterator() common.Iterater[Noder]
- func (tn *BoolNode) LinkChildren(children []Noder)
- func (tn *BoolNode) RemoveNode() []Noder
- func (tn *BoolNode) SetParent(parent Noder) bool
- func (tn *BoolNode) Size() int
- func (tn *BoolNode) String() string
- type BoolNodeIterator
- type ByteNode
- func (tn *ByteNode) AddChild(child Noder)
- func (tn *ByteNode) AddChildren(children []*ByteNode)
- func (tn *ByteNode) Cleanup()
- func (tn *ByteNode) Copy() common.Copier
- func (tn *ByteNode) DeleteChild(target Noder) []Noder
- func (tn *ByteNode) GetAncestors() []Noder
- func (tn *ByteNode) GetChildren() []Noder
- func (tn *ByteNode) GetFirstChild() Noder
- func (tn *ByteNode) GetFirstSibling() *ByteNode
- func (tn *ByteNode) GetLastSibling() *ByteNode
- func (tn *ByteNode) GetLeaves() []Noder
- func (tn *ByteNode) GetParent() Noder
- func (tn *ByteNode) HasChild(target *ByteNode) bool
- func (tn *ByteNode) IsChildOf(target *ByteNode) bool
- func (tn *ByteNode) IsLeaf() bool
- func (tn *ByteNode) IsRoot() bool
- func (tn *ByteNode) IsSingleton() bool
- func (tn *ByteNode) Iterator() common.Iterater[Noder]
- func (tn *ByteNode) LinkChildren(children []Noder)
- func (tn *ByteNode) RemoveNode() []Noder
- func (tn *ByteNode) SetParent(parent Noder) bool
- func (tn *ByteNode) Size() int
- func (tn *ByteNode) String() string
- type ByteNodeIterator
- type Complex128Node
- func (tn *Complex128Node) AddChild(child Noder)
- func (tn *Complex128Node) AddChildren(children []*Complex128Node)
- func (tn *Complex128Node) Cleanup()
- func (tn *Complex128Node) Copy() common.Copier
- func (tn *Complex128Node) DeleteChild(target Noder) []Noder
- func (tn *Complex128Node) GetAncestors() []Noder
- func (tn *Complex128Node) GetChildren() []Noder
- func (tn *Complex128Node) GetFirstChild() Noder
- func (tn *Complex128Node) GetFirstSibling() *Complex128Node
- func (tn *Complex128Node) GetLastSibling() *Complex128Node
- func (tn *Complex128Node) GetLeaves() []Noder
- func (tn *Complex128Node) GetParent() Noder
- func (tn *Complex128Node) HasChild(target *Complex128Node) bool
- func (tn *Complex128Node) IsChildOf(target *Complex128Node) bool
- func (tn *Complex128Node) IsLeaf() bool
- func (tn *Complex128Node) IsRoot() bool
- func (tn *Complex128Node) IsSingleton() bool
- func (tn *Complex128Node) Iterator() common.Iterater[Noder]
- func (tn *Complex128Node) LinkChildren(children []Noder)
- func (tn *Complex128Node) RemoveNode() []Noder
- func (tn *Complex128Node) SetParent(parent Noder) bool
- func (tn *Complex128Node) Size() int
- func (tn *Complex128Node) String() string
- type Complex128NodeIterator
- type Complex64Node
- func (tn *Complex64Node) AddChild(child Noder)
- func (tn *Complex64Node) AddChildren(children []*Complex64Node)
- func (tn *Complex64Node) Cleanup()
- func (tn *Complex64Node) Copy() common.Copier
- func (tn *Complex64Node) DeleteChild(target Noder) []Noder
- func (tn *Complex64Node) GetAncestors() []Noder
- func (tn *Complex64Node) GetChildren() []Noder
- func (tn *Complex64Node) GetFirstChild() Noder
- func (tn *Complex64Node) GetFirstSibling() *Complex64Node
- func (tn *Complex64Node) GetLastSibling() *Complex64Node
- func (tn *Complex64Node) GetLeaves() []Noder
- func (tn *Complex64Node) GetParent() Noder
- func (tn *Complex64Node) HasChild(target *Complex64Node) bool
- func (tn *Complex64Node) IsChildOf(target *Complex64Node) bool
- func (tn *Complex64Node) IsLeaf() bool
- func (tn *Complex64Node) IsRoot() bool
- func (tn *Complex64Node) IsSingleton() bool
- func (tn *Complex64Node) Iterator() common.Iterater[Noder]
- func (tn *Complex64Node) LinkChildren(children []Noder)
- func (tn *Complex64Node) RemoveNode() []Noder
- func (tn *Complex64Node) SetParent(parent Noder) bool
- func (tn *Complex64Node) Size() int
- func (tn *Complex64Node) String() string
- type Complex64NodeIterator
- type ErrorNode
- func (tn *ErrorNode) AddChild(child Noder)
- func (tn *ErrorNode) AddChildren(children []*ErrorNode)
- func (tn *ErrorNode) Cleanup()
- func (tn *ErrorNode) Copy() common.Copier
- func (tn *ErrorNode) DeleteChild(target Noder) []Noder
- func (tn *ErrorNode) GetAncestors() []Noder
- func (tn *ErrorNode) GetChildren() []Noder
- func (tn *ErrorNode) GetFirstChild() Noder
- func (tn *ErrorNode) GetFirstSibling() *ErrorNode
- func (tn *ErrorNode) GetLastSibling() *ErrorNode
- func (tn *ErrorNode) GetLeaves() []Noder
- func (tn *ErrorNode) GetParent() Noder
- func (tn *ErrorNode) HasChild(target *ErrorNode) bool
- func (tn *ErrorNode) IsChildOf(target *ErrorNode) bool
- func (tn *ErrorNode) IsLeaf() bool
- func (tn *ErrorNode) IsRoot() bool
- func (tn *ErrorNode) IsSingleton() bool
- func (tn *ErrorNode) Iterator() common.Iterater[Noder]
- func (tn *ErrorNode) LinkChildren(children []Noder)
- func (tn *ErrorNode) RemoveNode() []Noder
- func (tn *ErrorNode) SetParent(parent Noder) bool
- func (tn *ErrorNode) Size() int
- func (tn *ErrorNode) String() string
- type ErrorNodeIterator
- type Float32Node
- func (tn *Float32Node) AddChild(child Noder)
- func (tn *Float32Node) AddChildren(children []*Float32Node)
- func (tn *Float32Node) Cleanup()
- func (tn *Float32Node) Copy() common.Copier
- func (tn *Float32Node) DeleteChild(target Noder) []Noder
- func (tn *Float32Node) GetAncestors() []Noder
- func (tn *Float32Node) GetChildren() []Noder
- func (tn *Float32Node) GetFirstChild() Noder
- func (tn *Float32Node) GetFirstSibling() *Float32Node
- func (tn *Float32Node) GetLastSibling() *Float32Node
- func (tn *Float32Node) GetLeaves() []Noder
- func (tn *Float32Node) GetParent() Noder
- func (tn *Float32Node) HasChild(target *Float32Node) bool
- func (tn *Float32Node) IsChildOf(target *Float32Node) bool
- func (tn *Float32Node) IsLeaf() bool
- func (tn *Float32Node) IsRoot() bool
- func (tn *Float32Node) IsSingleton() bool
- func (tn *Float32Node) Iterator() common.Iterater[Noder]
- func (tn *Float32Node) LinkChildren(children []Noder)
- func (tn *Float32Node) RemoveNode() []Noder
- func (tn *Float32Node) SetParent(parent Noder) bool
- func (tn *Float32Node) Size() int
- func (tn *Float32Node) String() string
- type Float32NodeIterator
- type Float64Node
- func (tn *Float64Node) AddChild(child Noder)
- func (tn *Float64Node) AddChildren(children []*Float64Node)
- func (tn *Float64Node) Cleanup()
- func (tn *Float64Node) Copy() common.Copier
- func (tn *Float64Node) DeleteChild(target Noder) []Noder
- func (tn *Float64Node) GetAncestors() []Noder
- func (tn *Float64Node) GetChildren() []Noder
- func (tn *Float64Node) GetFirstChild() Noder
- func (tn *Float64Node) GetFirstSibling() *Float64Node
- func (tn *Float64Node) GetLastSibling() *Float64Node
- func (tn *Float64Node) GetLeaves() []Noder
- func (tn *Float64Node) GetParent() Noder
- func (tn *Float64Node) HasChild(target *Float64Node) bool
- func (tn *Float64Node) IsChildOf(target *Float64Node) bool
- func (tn *Float64Node) IsLeaf() bool
- func (tn *Float64Node) IsRoot() bool
- func (tn *Float64Node) IsSingleton() bool
- func (tn *Float64Node) Iterator() common.Iterater[Noder]
- func (tn *Float64Node) LinkChildren(children []Noder)
- func (tn *Float64Node) RemoveNode() []Noder
- func (tn *Float64Node) SetParent(parent Noder) bool
- func (tn *Float64Node) Size() int
- func (tn *Float64Node) String() string
- type Float64NodeIterator
- type Int16Node
- func (tn *Int16Node) AddChild(child Noder)
- func (tn *Int16Node) AddChildren(children []*Int16Node)
- func (tn *Int16Node) Cleanup()
- func (tn *Int16Node) Copy() common.Copier
- func (tn *Int16Node) DeleteChild(target Noder) []Noder
- func (tn *Int16Node) GetAncestors() []Noder
- func (tn *Int16Node) GetChildren() []Noder
- func (tn *Int16Node) GetFirstChild() Noder
- func (tn *Int16Node) GetFirstSibling() *Int16Node
- func (tn *Int16Node) GetLastSibling() *Int16Node
- func (tn *Int16Node) GetLeaves() []Noder
- func (tn *Int16Node) GetParent() Noder
- func (tn *Int16Node) HasChild(target *Int16Node) bool
- func (tn *Int16Node) IsChildOf(target *Int16Node) bool
- func (tn *Int16Node) IsLeaf() bool
- func (tn *Int16Node) IsRoot() bool
- func (tn *Int16Node) IsSingleton() bool
- func (tn *Int16Node) Iterator() common.Iterater[Noder]
- func (tn *Int16Node) LinkChildren(children []Noder)
- func (tn *Int16Node) RemoveNode() []Noder
- func (tn *Int16Node) SetParent(parent Noder) bool
- func (tn *Int16Node) Size() int
- func (tn *Int16Node) String() string
- type Int16NodeIterator
- type Int32Node
- func (tn *Int32Node) AddChild(child Noder)
- func (tn *Int32Node) AddChildren(children []*Int32Node)
- func (tn *Int32Node) Cleanup()
- func (tn *Int32Node) Copy() common.Copier
- func (tn *Int32Node) DeleteChild(target Noder) []Noder
- func (tn *Int32Node) GetAncestors() []Noder
- func (tn *Int32Node) GetChildren() []Noder
- func (tn *Int32Node) GetFirstChild() Noder
- func (tn *Int32Node) GetFirstSibling() *Int32Node
- func (tn *Int32Node) GetLastSibling() *Int32Node
- func (tn *Int32Node) GetLeaves() []Noder
- func (tn *Int32Node) GetParent() Noder
- func (tn *Int32Node) HasChild(target *Int32Node) bool
- func (tn *Int32Node) IsChildOf(target *Int32Node) bool
- func (tn *Int32Node) IsLeaf() bool
- func (tn *Int32Node) IsRoot() bool
- func (tn *Int32Node) IsSingleton() bool
- func (tn *Int32Node) Iterator() common.Iterater[Noder]
- func (tn *Int32Node) LinkChildren(children []Noder)
- func (tn *Int32Node) RemoveNode() []Noder
- func (tn *Int32Node) SetParent(parent Noder) bool
- func (tn *Int32Node) Size() int
- func (tn *Int32Node) String() string
- type Int32NodeIterator
- type Int64Node
- func (tn *Int64Node) AddChild(child Noder)
- func (tn *Int64Node) AddChildren(children []*Int64Node)
- func (tn *Int64Node) Cleanup()
- func (tn *Int64Node) Copy() common.Copier
- func (tn *Int64Node) DeleteChild(target Noder) []Noder
- func (tn *Int64Node) GetAncestors() []Noder
- func (tn *Int64Node) GetChildren() []Noder
- func (tn *Int64Node) GetFirstChild() Noder
- func (tn *Int64Node) GetFirstSibling() *Int64Node
- func (tn *Int64Node) GetLastSibling() *Int64Node
- func (tn *Int64Node) GetLeaves() []Noder
- func (tn *Int64Node) GetParent() Noder
- func (tn *Int64Node) HasChild(target *Int64Node) bool
- func (tn *Int64Node) IsChildOf(target *Int64Node) bool
- func (tn *Int64Node) IsLeaf() bool
- func (tn *Int64Node) IsRoot() bool
- func (tn *Int64Node) IsSingleton() bool
- func (tn *Int64Node) Iterator() common.Iterater[Noder]
- func (tn *Int64Node) LinkChildren(children []Noder)
- func (tn *Int64Node) RemoveNode() []Noder
- func (tn *Int64Node) SetParent(parent Noder) bool
- func (tn *Int64Node) Size() int
- func (tn *Int64Node) String() string
- type Int64NodeIterator
- type Int8Node
- func (tn *Int8Node) AddChild(child Noder)
- func (tn *Int8Node) AddChildren(children []*Int8Node)
- func (tn *Int8Node) Cleanup()
- func (tn *Int8Node) Copy() common.Copier
- func (tn *Int8Node) DeleteChild(target Noder) []Noder
- func (tn *Int8Node) GetAncestors() []Noder
- func (tn *Int8Node) GetChildren() []Noder
- func (tn *Int8Node) GetFirstChild() Noder
- func (tn *Int8Node) GetFirstSibling() *Int8Node
- func (tn *Int8Node) GetLastSibling() *Int8Node
- func (tn *Int8Node) GetLeaves() []Noder
- func (tn *Int8Node) GetParent() Noder
- func (tn *Int8Node) HasChild(target *Int8Node) bool
- func (tn *Int8Node) IsChildOf(target *Int8Node) bool
- func (tn *Int8Node) IsLeaf() bool
- func (tn *Int8Node) IsRoot() bool
- func (tn *Int8Node) IsSingleton() bool
- func (tn *Int8Node) Iterator() common.Iterater[Noder]
- func (tn *Int8Node) LinkChildren(children []Noder)
- func (tn *Int8Node) RemoveNode() []Noder
- func (tn *Int8Node) SetParent(parent Noder) bool
- func (tn *Int8Node) Size() int
- func (tn *Int8Node) String() string
- type Int8NodeIterator
- type IntNode
- func (tn *IntNode) AddChild(child Noder)
- func (tn *IntNode) AddChildren(children []*IntNode)
- func (tn *IntNode) Cleanup()
- func (tn *IntNode) Copy() common.Copier
- func (tn *IntNode) DeleteChild(target Noder) []Noder
- func (tn *IntNode) GetAncestors() []Noder
- func (tn *IntNode) GetChildren() []Noder
- func (tn *IntNode) GetFirstChild() Noder
- func (tn *IntNode) GetFirstSibling() *IntNode
- func (tn *IntNode) GetLastSibling() *IntNode
- func (tn *IntNode) GetLeaves() []Noder
- func (tn *IntNode) GetParent() Noder
- func (tn *IntNode) HasChild(target *IntNode) bool
- func (tn *IntNode) IsChildOf(target *IntNode) bool
- func (tn *IntNode) IsLeaf() bool
- func (tn *IntNode) IsRoot() bool
- func (tn *IntNode) IsSingleton() bool
- func (tn *IntNode) Iterator() common.Iterater[Noder]
- func (tn *IntNode) LinkChildren(children []Noder)
- func (tn *IntNode) RemoveNode() []Noder
- func (tn *IntNode) SetParent(parent Noder) bool
- func (tn *IntNode) Size() int
- func (tn *IntNode) String() string
- type IntNodeIterator
- type Noder
- type RuneNode
- func (tn *RuneNode) AddChild(child Noder)
- func (tn *RuneNode) AddChildren(children []*RuneNode)
- func (tn *RuneNode) Cleanup()
- func (tn *RuneNode) Copy() common.Copier
- func (tn *RuneNode) DeleteChild(target Noder) []Noder
- func (tn *RuneNode) GetAncestors() []Noder
- func (tn *RuneNode) GetChildren() []Noder
- func (tn *RuneNode) GetFirstChild() Noder
- func (tn *RuneNode) GetFirstSibling() *RuneNode
- func (tn *RuneNode) GetLastSibling() *RuneNode
- func (tn *RuneNode) GetLeaves() []Noder
- func (tn *RuneNode) GetParent() Noder
- func (tn *RuneNode) HasChild(target *RuneNode) bool
- func (tn *RuneNode) IsChildOf(target *RuneNode) bool
- func (tn *RuneNode) IsLeaf() bool
- func (tn *RuneNode) IsRoot() bool
- func (tn *RuneNode) IsSingleton() bool
- func (tn *RuneNode) Iterator() common.Iterater[Noder]
- func (tn *RuneNode) LinkChildren(children []Noder)
- func (tn *RuneNode) RemoveNode() []Noder
- func (tn *RuneNode) SetParent(parent Noder) bool
- func (tn *RuneNode) Size() int
- func (tn *RuneNode) String() string
- type RuneNodeIterator
- type StatusNode
- func (tn *StatusNode[S, T]) AddChild(child Noder)
- func (tn *StatusNode[S, T]) AddChildren(children []*StatusNode[S, T])
- func (tn *StatusNode[S, T]) Cleanup()
- func (tn *StatusNode[S, T]) Copy() common.Copier
- func (tn *StatusNode[S, T]) DeleteChild(target Noder) []Noder
- func (tn *StatusNode[S, T]) GetAncestors() []Noder
- func (tn *StatusNode[S, T]) GetChildren() []Noder
- func (tn *StatusNode[S, T]) GetFirstChild() Noder
- func (tn *StatusNode[S, T]) GetFirstSibling() *StatusNode[S, T]
- func (tn *StatusNode[S, T]) GetLastSibling() *StatusNode[S, T]
- func (tn *StatusNode[S, T]) GetLeaves() []Noder
- func (tn *StatusNode[S, T]) GetParent() Noder
- func (tn *StatusNode[S, T]) HasChild(target *StatusNode[S, T]) bool
- func (tn *StatusNode[S, T]) IsChildOf(target *StatusNode[S, T]) bool
- func (tn *StatusNode[S, T]) IsLeaf() bool
- func (tn *StatusNode[S, T]) IsRoot() bool
- func (tn *StatusNode[S, T]) IsSingleton() bool
- func (tn *StatusNode[S, T]) Iterator() common.Iterater[Noder]
- func (tn *StatusNode[S, T]) LinkChildren(children []Noder)
- func (tn *StatusNode[S, T]) RemoveNode() []Noder
- func (tn *StatusNode[S, T]) SetParent(parent Noder) bool
- func (tn *StatusNode[S, T]) Size() int
- func (tn *StatusNode[S, T]) String() string
- type StatusNodeIterator
- type StringNode
- func (tn *StringNode) AddChild(child Noder)
- func (tn *StringNode) AddChildren(children []*StringNode)
- func (tn *StringNode) Cleanup()
- func (tn *StringNode) Copy() common.Copier
- func (tn *StringNode) DeleteChild(target Noder) []Noder
- func (tn *StringNode) GetAncestors() []Noder
- func (tn *StringNode) GetChildren() []Noder
- func (tn *StringNode) GetFirstChild() Noder
- func (tn *StringNode) GetFirstSibling() *StringNode
- func (tn *StringNode) GetLastSibling() *StringNode
- func (tn *StringNode) GetLeaves() []Noder
- func (tn *StringNode) GetParent() Noder
- func (tn *StringNode) HasChild(target *StringNode) bool
- func (tn *StringNode) IsChildOf(target *StringNode) bool
- func (tn *StringNode) IsLeaf() bool
- func (tn *StringNode) IsRoot() bool
- func (tn *StringNode) IsSingleton() bool
- func (tn *StringNode) Iterator() common.Iterater[Noder]
- func (tn *StringNode) LinkChildren(children []Noder)
- func (tn *StringNode) RemoveNode() []Noder
- func (tn *StringNode) SetParent(parent Noder) bool
- func (tn *StringNode) Size() int
- func (tn *StringNode) String() string
- type StringNodeIterator
- type TreeNode
- func (tn *TreeNode[T]) AddChild(child Noder)
- func (tn *TreeNode[T]) AddChildren(children []*TreeNode[T])
- func (tn *TreeNode[T]) Cleanup()
- func (tn *TreeNode[T]) Copy() common.Copier
- func (tn *TreeNode[T]) DeleteChild(target Noder) []Noder
- func (tn *TreeNode[T]) GetAncestors() []Noder
- func (tn *TreeNode[T]) GetChildren() []Noder
- func (tn *TreeNode[T]) GetFirstChild() Noder
- func (tn *TreeNode[T]) GetFirstSibling() *TreeNode[T]
- func (tn *TreeNode[T]) GetLastSibling() *TreeNode[T]
- func (tn *TreeNode[T]) GetLeaves() []Noder
- func (tn *TreeNode[T]) GetParent() Noder
- func (tn *TreeNode[T]) HasChild(target *TreeNode[T]) bool
- func (tn *TreeNode[T]) IsChildOf(target *TreeNode[T]) bool
- func (tn *TreeNode[T]) IsLeaf() bool
- func (tn *TreeNode[T]) IsRoot() bool
- func (tn *TreeNode[T]) IsSingleton() bool
- func (tn *TreeNode[T]) Iterator() common.Iterater[Noder]
- func (tn *TreeNode[T]) LinkChildren(children []Noder)
- func (tn *TreeNode[T]) RemoveNode() []Noder
- func (tn *TreeNode[T]) SetParent(parent Noder) bool
- func (tn *TreeNode[T]) Size() int
- func (tn *TreeNode[T]) String() string
- type TreeNodeIterator
- type Uint16Node
- func (tn *Uint16Node) AddChild(child Noder)
- func (tn *Uint16Node) AddChildren(children []*Uint16Node)
- func (tn *Uint16Node) Cleanup()
- func (tn *Uint16Node) Copy() common.Copier
- func (tn *Uint16Node) DeleteChild(target Noder) []Noder
- func (tn *Uint16Node) GetAncestors() []Noder
- func (tn *Uint16Node) GetChildren() []Noder
- func (tn *Uint16Node) GetFirstChild() Noder
- func (tn *Uint16Node) GetFirstSibling() *Uint16Node
- func (tn *Uint16Node) GetLastSibling() *Uint16Node
- func (tn *Uint16Node) GetLeaves() []Noder
- func (tn *Uint16Node) GetParent() Noder
- func (tn *Uint16Node) HasChild(target *Uint16Node) bool
- func (tn *Uint16Node) IsChildOf(target *Uint16Node) bool
- func (tn *Uint16Node) IsLeaf() bool
- func (tn *Uint16Node) IsRoot() bool
- func (tn *Uint16Node) IsSingleton() bool
- func (tn *Uint16Node) Iterator() common.Iterater[Noder]
- func (tn *Uint16Node) LinkChildren(children []Noder)
- func (tn *Uint16Node) RemoveNode() []Noder
- func (tn *Uint16Node) SetParent(parent Noder) bool
- func (tn *Uint16Node) Size() int
- func (tn *Uint16Node) String() string
- type Uint16NodeIterator
- type Uint32Node
- func (tn *Uint32Node) AddChild(child Noder)
- func (tn *Uint32Node) AddChildren(children []*Uint32Node)
- func (tn *Uint32Node) Cleanup()
- func (tn *Uint32Node) Copy() common.Copier
- func (tn *Uint32Node) DeleteChild(target Noder) []Noder
- func (tn *Uint32Node) GetAncestors() []Noder
- func (tn *Uint32Node) GetChildren() []Noder
- func (tn *Uint32Node) GetFirstChild() Noder
- func (tn *Uint32Node) GetFirstSibling() *Uint32Node
- func (tn *Uint32Node) GetLastSibling() *Uint32Node
- func (tn *Uint32Node) GetLeaves() []Noder
- func (tn *Uint32Node) GetParent() Noder
- func (tn *Uint32Node) HasChild(target *Uint32Node) bool
- func (tn *Uint32Node) IsChildOf(target *Uint32Node) bool
- func (tn *Uint32Node) IsLeaf() bool
- func (tn *Uint32Node) IsRoot() bool
- func (tn *Uint32Node) IsSingleton() bool
- func (tn *Uint32Node) Iterator() common.Iterater[Noder]
- func (tn *Uint32Node) LinkChildren(children []Noder)
- func (tn *Uint32Node) RemoveNode() []Noder
- func (tn *Uint32Node) SetParent(parent Noder) bool
- func (tn *Uint32Node) Size() int
- func (tn *Uint32Node) String() string
- type Uint32NodeIterator
- type Uint64Node
- func (tn *Uint64Node) AddChild(child Noder)
- func (tn *Uint64Node) AddChildren(children []*Uint64Node)
- func (tn *Uint64Node) Cleanup()
- func (tn *Uint64Node) Copy() common.Copier
- func (tn *Uint64Node) DeleteChild(target Noder) []Noder
- func (tn *Uint64Node) GetAncestors() []Noder
- func (tn *Uint64Node) GetChildren() []Noder
- func (tn *Uint64Node) GetFirstChild() Noder
- func (tn *Uint64Node) GetFirstSibling() *Uint64Node
- func (tn *Uint64Node) GetLastSibling() *Uint64Node
- func (tn *Uint64Node) GetLeaves() []Noder
- func (tn *Uint64Node) GetParent() Noder
- func (tn *Uint64Node) HasChild(target *Uint64Node) bool
- func (tn *Uint64Node) IsChildOf(target *Uint64Node) bool
- func (tn *Uint64Node) IsLeaf() bool
- func (tn *Uint64Node) IsRoot() bool
- func (tn *Uint64Node) IsSingleton() bool
- func (tn *Uint64Node) Iterator() common.Iterater[Noder]
- func (tn *Uint64Node) LinkChildren(children []Noder)
- func (tn *Uint64Node) RemoveNode() []Noder
- func (tn *Uint64Node) SetParent(parent Noder) bool
- func (tn *Uint64Node) Size() int
- func (tn *Uint64Node) String() string
- type Uint64NodeIterator
- type Uint8Node
- func (tn *Uint8Node) AddChild(child Noder)
- func (tn *Uint8Node) AddChildren(children []*Uint8Node)
- func (tn *Uint8Node) Cleanup()
- func (tn *Uint8Node) Copy() common.Copier
- func (tn *Uint8Node) DeleteChild(target Noder) []Noder
- func (tn *Uint8Node) GetAncestors() []Noder
- func (tn *Uint8Node) GetChildren() []Noder
- func (tn *Uint8Node) GetFirstChild() Noder
- func (tn *Uint8Node) GetFirstSibling() *Uint8Node
- func (tn *Uint8Node) GetLastSibling() *Uint8Node
- func (tn *Uint8Node) GetLeaves() []Noder
- func (tn *Uint8Node) GetParent() Noder
- func (tn *Uint8Node) HasChild(target *Uint8Node) bool
- func (tn *Uint8Node) IsChildOf(target *Uint8Node) bool
- func (tn *Uint8Node) IsLeaf() bool
- func (tn *Uint8Node) IsRoot() bool
- func (tn *Uint8Node) IsSingleton() bool
- func (tn *Uint8Node) Iterator() common.Iterater[Noder]
- func (tn *Uint8Node) LinkChildren(children []Noder)
- func (tn *Uint8Node) RemoveNode() []Noder
- func (tn *Uint8Node) SetParent(parent Noder) bool
- func (tn *Uint8Node) Size() int
- func (tn *Uint8Node) String() string
- type Uint8NodeIterator
- type UintNode
- func (tn *UintNode) AddChild(child Noder)
- func (tn *UintNode) AddChildren(children []*UintNode)
- func (tn *UintNode) Cleanup()
- func (tn *UintNode) Copy() common.Copier
- func (tn *UintNode) DeleteChild(target Noder) []Noder
- func (tn *UintNode) GetAncestors() []Noder
- func (tn *UintNode) GetChildren() []Noder
- func (tn *UintNode) GetFirstChild() Noder
- func (tn *UintNode) GetFirstSibling() *UintNode
- func (tn *UintNode) GetLastSibling() *UintNode
- func (tn *UintNode) GetLeaves() []Noder
- func (tn *UintNode) GetParent() Noder
- func (tn *UintNode) HasChild(target *UintNode) bool
- func (tn *UintNode) IsChildOf(target *UintNode) bool
- func (tn *UintNode) IsLeaf() bool
- func (tn *UintNode) IsRoot() bool
- func (tn *UintNode) IsSingleton() bool
- func (tn *UintNode) Iterator() common.Iterater[Noder]
- func (tn *UintNode) LinkChildren(children []Noder)
- func (tn *UintNode) RemoveNode() []Noder
- func (tn *UintNode) SetParent(parent Noder) bool
- func (tn *UintNode) Size() int
- func (tn *UintNode) String() string
- type UintNodeIterator
- type UintptrNode
- func (tn *UintptrNode) AddChild(child Noder)
- func (tn *UintptrNode) AddChildren(children []*UintptrNode)
- func (tn *UintptrNode) Cleanup()
- func (tn *UintptrNode) Copy() common.Copier
- func (tn *UintptrNode) DeleteChild(target Noder) []Noder
- func (tn *UintptrNode) GetAncestors() []Noder
- func (tn *UintptrNode) GetChildren() []Noder
- func (tn *UintptrNode) GetFirstChild() Noder
- func (tn *UintptrNode) GetFirstSibling() *UintptrNode
- func (tn *UintptrNode) GetLastSibling() *UintptrNode
- func (tn *UintptrNode) GetLeaves() []Noder
- func (tn *UintptrNode) GetParent() Noder
- func (tn *UintptrNode) HasChild(target *UintptrNode) bool
- func (tn *UintptrNode) IsChildOf(target *UintptrNode) bool
- func (tn *UintptrNode) IsLeaf() bool
- func (tn *UintptrNode) IsRoot() bool
- func (tn *UintptrNode) IsSingleton() bool
- func (tn *UintptrNode) Iterator() common.Iterater[Noder]
- func (tn *UintptrNode) LinkChildren(children []Noder)
- func (tn *UintptrNode) RemoveNode() []Noder
- func (tn *UintptrNode) SetParent(parent Noder) bool
- func (tn *UintptrNode) Size() int
- func (tn *UintptrNode) String() string
- type UintptrNodeIterator
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
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
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
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
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
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*BoolNode) GetAncestors ¶ added in v0.1.1
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
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
GetFirstChild implements the Noder interface.
func (*BoolNode) GetFirstSibling ¶ added in v0.1.1
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
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
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) HasChild ¶ added in v0.1.1
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
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) IsRoot ¶ added in v0.1.1
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
IsSingleton implements the Noder interface.
func (*BoolNode) Iterator ¶ added in v0.1.1
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
LinkWithParent implements the Noder interface.
Children that are not of type *BoolNode or nil are ignored.
func (*BoolNode) RemoveNode ¶ added in v0.1.1
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) Size ¶ added in v0.1.1
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.
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
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
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
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
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
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*ByteNode) GetAncestors ¶ added in v0.1.1
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
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
GetFirstChild implements the Noder interface.
func (*ByteNode) GetFirstSibling ¶ added in v0.1.1
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
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
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) HasChild ¶ added in v0.1.1
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
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) IsRoot ¶ added in v0.1.1
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
IsSingleton implements the Noder interface.
func (*ByteNode) Iterator ¶ added in v0.1.1
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
LinkWithParent implements the Noder interface.
Children that are not of type *ByteNode or nil are ignored.
func (*ByteNode) RemoveNode ¶ added in v0.1.1
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) Size ¶ added in v0.1.1
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.
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
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
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
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
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
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*ErrorNode) GetAncestors ¶ added in v0.1.1
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
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
GetFirstChild implements the Noder interface.
func (*ErrorNode) GetFirstSibling ¶ added in v0.1.1
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
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
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) HasChild ¶ added in v0.1.1
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
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) IsRoot ¶ added in v0.1.1
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
IsSingleton implements the Noder interface.
func (*ErrorNode) Iterator ¶ added in v0.1.1
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
LinkWithParent implements the Noder interface.
Children that are not of type *ErrorNode or nil are ignored.
func (*ErrorNode) RemoveNode ¶ added in v0.1.1
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) Size ¶ added in v0.1.1
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.
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
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
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
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
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
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*Int16Node) GetAncestors ¶ added in v0.1.1
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
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
GetFirstChild implements the Noder interface.
func (*Int16Node) GetFirstSibling ¶ added in v0.1.1
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
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
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) HasChild ¶ added in v0.1.1
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
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) IsRoot ¶ added in v0.1.1
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
IsSingleton implements the Noder interface.
func (*Int16Node) Iterator ¶ added in v0.1.1
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
LinkWithParent implements the Noder interface.
Children that are not of type *Int16Node or nil are ignored.
func (*Int16Node) RemoveNode ¶ added in v0.1.1
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) Size ¶ added in v0.1.1
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.
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
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
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
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
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
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*Int32Node) GetAncestors ¶ added in v0.1.1
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
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
GetFirstChild implements the Noder interface.
func (*Int32Node) GetFirstSibling ¶ added in v0.1.1
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
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
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) HasChild ¶ added in v0.1.1
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
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) IsRoot ¶ added in v0.1.1
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
IsSingleton implements the Noder interface.
func (*Int32Node) Iterator ¶ added in v0.1.1
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
LinkWithParent implements the Noder interface.
Children that are not of type *Int32Node or nil are ignored.
func (*Int32Node) RemoveNode ¶ added in v0.1.1
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) Size ¶ added in v0.1.1
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.
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
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
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
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
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
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*Int64Node) GetAncestors ¶ added in v0.1.1
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
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
GetFirstChild implements the Noder interface.
func (*Int64Node) GetFirstSibling ¶ added in v0.1.1
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
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
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) HasChild ¶ added in v0.1.1
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
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) IsRoot ¶ added in v0.1.1
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
IsSingleton implements the Noder interface.
func (*Int64Node) Iterator ¶ added in v0.1.1
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
LinkWithParent implements the Noder interface.
Children that are not of type *Int64Node or nil are ignored.
func (*Int64Node) RemoveNode ¶ added in v0.1.1
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) Size ¶ added in v0.1.1
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.
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
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
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
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
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
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*Int8Node) GetAncestors ¶ added in v0.1.1
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
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
GetFirstChild implements the Noder interface.
func (*Int8Node) GetFirstSibling ¶ added in v0.1.1
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
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
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) HasChild ¶ added in v0.1.1
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
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) IsRoot ¶ added in v0.1.1
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
IsSingleton implements the Noder interface.
func (*Int8Node) Iterator ¶ added in v0.1.1
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
LinkWithParent implements the Noder interface.
Children that are not of type *Int8Node or nil are ignored.
func (*Int8Node) RemoveNode ¶ added in v0.1.1
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) Size ¶ added in v0.1.1
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.
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
IntNode is a node in a tree.
func NewIntNode ¶ added in v0.1.1
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
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
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
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
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*IntNode) GetAncestors ¶ added in v0.1.1
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
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
GetFirstChild implements the Noder interface.
func (*IntNode) GetFirstSibling ¶ added in v0.1.1
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
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
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) HasChild ¶ added in v0.1.1
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
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) IsRoot ¶ added in v0.1.1
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
IsSingleton implements the Noder interface.
func (*IntNode) Iterator ¶ added in v0.1.1
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
LinkWithParent implements the Noder interface.
Children that are not of type *IntNode or nil are ignored.
func (*IntNode) RemoveNode ¶ added in v0.1.1
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) Size ¶ added in v0.1.1
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.
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
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
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
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
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
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*RuneNode) GetAncestors ¶ added in v0.1.1
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
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
GetFirstChild implements the Noder interface.
func (*RuneNode) GetFirstSibling ¶ added in v0.1.1
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
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
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) HasChild ¶ added in v0.1.1
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
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) IsRoot ¶ added in v0.1.1
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
IsSingleton implements the Noder interface.
func (*RuneNode) Iterator ¶ added in v0.1.1
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
LinkWithParent implements the Noder interface.
Children that are not of type *RuneNode or nil are ignored.
func (*RuneNode) RemoveNode ¶ added in v0.1.1
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) Size ¶ added in v0.1.1
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.
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 ¶
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 ¶
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 ¶
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 ¶
Copy implements the Noder interface.
It never returns nil and it does not copy the parent or the sibling pointers.
func (*TreeNode[T]) DeleteChild ¶
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*TreeNode[T]) GetAncestors ¶
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 ¶
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 ¶
GetFirstChild implements the Noder interface.
func (*TreeNode[T]) GetFirstSibling ¶
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 ¶
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 ¶
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]) HasChild ¶
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 ¶
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]) IsRoot ¶
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 ¶
IsSingleton implements the Noder interface.
func (*TreeNode[T]) Iterator ¶
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 ¶
LinkWithParent implements the Noder interface.
Children that are not of type *TreeNode[T] or nil are ignored.
func (*TreeNode[T]) RemoveNode ¶
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]) Size ¶
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.
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
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
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
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
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
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*Uint8Node) GetAncestors ¶ added in v0.1.1
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
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
GetFirstChild implements the Noder interface.
func (*Uint8Node) GetFirstSibling ¶ added in v0.1.1
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
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
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) HasChild ¶ added in v0.1.1
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
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) IsRoot ¶ added in v0.1.1
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
IsSingleton implements the Noder interface.
func (*Uint8Node) Iterator ¶ added in v0.1.1
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
LinkWithParent implements the Noder interface.
Children that are not of type *Uint8Node or nil are ignored.
func (*Uint8Node) RemoveNode ¶ added in v0.1.1
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) Size ¶ added in v0.1.1
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.
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
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
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
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
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
DeleteChild implements the Noder interface.
No nil nodes are returned.
func (*UintNode) GetAncestors ¶ added in v0.1.1
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
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
GetFirstChild implements the Noder interface.
func (*UintNode) GetFirstSibling ¶ added in v0.1.1
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
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
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) HasChild ¶ added in v0.1.1
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
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) IsRoot ¶ added in v0.1.1
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
IsSingleton implements the Noder interface.
func (*UintNode) Iterator ¶ added in v0.1.1
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
LinkWithParent implements the Noder interface.
Children that are not of type *UintNode or nil are ignored.
func (*UintNode) RemoveNode ¶ added in v0.1.1
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) Size ¶ added in v0.1.1
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.
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.