Table of Contents

Class BaseTreeNode<TValue, TTree, TTreeNode>

Namespace
Garyon.DataStructures.Trees
Assembly
Garyon.dll

Represents a tree node, which is a component that is contained within a tree.

public abstract class BaseTreeNode<TValue, TTree, TTreeNode> : ITreeNode<TValue, TTree, TTreeNode>, ITreeNode<TValue>, IEnumerable<TValue>, IEnumerable where TTree : BaseTree<TValue, TTree, TTreeNode> where TTreeNode : BaseTreeNode<TValue, TTree, TTreeNode>

Type Parameters

TValue

The type of the value that is stored in the node.

TTree

The type of the tree that this type is used in.

TTreeNode

The type of the tree nodes that are used in the TTree type.

Inheritance
BaseTreeNode<TValue, TTree, TTreeNode>
Implements
ITreeNode<TValue, TTree, TTreeNode>
ITreeNode<TValue>
IEnumerable<TValue>
Derived
Inherited Members
Extension Methods

Constructors

BaseTreeNode(TValue)

Initializes a new instance of the TreeNode<T> class with no base tree or parent node.

protected BaseTreeNode(TValue value = default)

Parameters

value TValue

The value of the node.

BaseTreeNode(TTree, TValue)

Initializes a new instance of the TreeNode<T> class with a base tree, but no parent node.

protected BaseTreeNode(TTree baseTree, TValue value = default)

Parameters

baseTree TTree

The base tree that contains this node.

value TValue

The value of the node.

BaseTreeNode(TTreeNode, TValue)

Initializes a new instance of the TreeNode<T> class with a parent node. The base tree is considered to be that of the parent.

protected BaseTreeNode(TTreeNode parentNode, TValue value = default)

Parameters

parentNode TTreeNode

The parent node.

value TValue

The value of the node.

Fields

InternalBaseTree

The internal base tree. Prefer using this instead of calling the property for internal usage, unless the BaseTree setter is required.

protected TTree InternalBaseTree

Field Value

TTree

InternalParent

The internal parent. Prefer using this instead of calling the property for internal usage, unless the Parent setter is required.

protected TTreeNode InternalParent

Field Value

TTreeNode

Properties

BaseTree

Gets or sets the base tree that contains this node.

public virtual TTree BaseTree { get; set; }

Property Value

TTree

BaseTreeHeight

Gets the height of this tree node's base tree height. It is equal to the sum of this tree node's height and depth.

public int BaseTreeHeight { get; }

Property Value

int

Breadth

Gets the breadth of this tree node.

public int Breadth { get; }

Property Value

int

Children

Gets or sets the children nodes of this tree.

public abstract List<TTreeNode> Children { get; set; }

Property Value

List<TTreeNode>

The new list of nodes to set the children to.

ChildrenCount

Gets the count of children of this node; prefer calling this property instead of getting the count directly from the respective property to retrieve the children.

public abstract int ChildrenCount { get; }

Property Value

int

Depth

Gets the depth of this tree node.

public int Depth { get; }

Property Value

int

Descendants

Gets the descendants of this tree node.

public int Descendants { get; }

Property Value

int

Height

Gets the height of this tree node's subtree.

public abstract int Height { get; }

Property Value

int

IsLeaf

Determines whether this node is a leaf; that is, it has no children.

public bool IsLeaf { get; }

Property Value

bool

IsRoot

Determines whether this node is the root; that is, its parent is null.

public bool IsRoot { get; }

Property Value

bool

Parent

Gets or sets the parent node of this tree node.

public virtual TTreeNode Parent { get; set; }

Property Value

TTreeNode

This

Gets this tree node instance as a TTreeNode.

protected TTreeNode This { get; }

Property Value

TTreeNode

Value

The value of the node.

public TValue Value { get; set; }

Property Value

TValue

Methods

AddChildrenToClonedInstance(TTreeNode)

Clones this tree node's children to the cloned instance that is created within the Clone() method.

protected abstract void AddChildrenToClonedInstance(TTreeNode result)

Parameters

result TTreeNode

The resulting instance to which to add the cloned children.

Remarks

The cloned children should also be cloned with the Clone(bool) method, but with the argument being false.

Clone()

Clones this TreeNode<T> and all its children recursively.

public TTreeNode Clone()

Returns

TTreeNode

The cloned TreeNode<T>. Its base tree is also equal to the original TreeNode<T>'s base tree.

Clone(bool)

Clones this TreeNode<T> and all its children recursively.

protected TTreeNode Clone(bool setBaseTree)

Parameters

setBaseTree bool

Determines whether to set the base tree on the cloned instance.

Returns

TTreeNode

The cloned TreeNode<T>. Its base tree is also equal to the original TreeNode<T>'s base tree.

GetChild(TValue)

Gets a direct child of this node that has the specified value.

public abstract TTreeNode GetChild(TValue value)

Parameters

value TValue

The value of the direct child node to find.

Returns

TTreeNode

The TreeNode<T> with the specified value, if found; otherwise null.

GetEnumerator()

Gets an enumerator that traverses the subtree using pre-order traversal.

public IEnumerator<TValue> GetEnumerator()

Returns

IEnumerator<TValue>

The IEnumerator<T> that traverses the subtree using pre-order traversal.

GetHashCode()

Gets the hash code of this tree node, which is equal to the hash code of the value of this node.

public override int GetHashCode()

Returns

int

This tree node's hash code.

GetNode(IEnumerable<TTreeNode>, TValue)

Gets the first node that has the specified value from the specified collection.

protected static TTreeNode GetNode(IEnumerable<TTreeNode> collection, TValue value)

Parameters

collection IEnumerable<TTreeNode>

The collection that may contain the requested value.

value TValue

The value to find in the collection's nodes.

Returns

TTreeNode

The first node that was found in the collection, or null, if it was not found.

GetNode(TValue)

Gets a node from the subtree with this tree node as a root node that has the specified value.

public virtual TTreeNode GetNode(TValue value)

Parameters

value TValue

The value of the tree node to find.

Returns

TTreeNode

The TreeNode<T> with the specified value, if found; otherwise null.

GetTreeView(int)

Gets the tree view of this tree node as a subtree.

public string GetTreeView(int childIndent = 4)

Parameters

childIndent int

The length of the indentation for each subsequent child.

Returns

string

The tree view.

InitializeNewNode(TValue)

Initializes a new instance of the TreeNode<T> class with no base tree or parent node.

protected abstract TTreeNode InitializeNewNode(TValue value = default)

Parameters

value TValue

The value of the node.

Returns

TTreeNode

InitializeNewNode(TTree, TValue)

Initializes a new instance of the TreeNode<T> class with a base tree, but no parent node.

protected abstract TTreeNode InitializeNewNode(TTree baseTree, TValue value = default)

Parameters

baseTree TTree

The base tree that contains this node.

value TValue

The value of the node.

Returns

TTreeNode

InitializeNewNode(TTreeNode, TValue)

Initializes a new instance of the TreeNode<T> class with a parent node. The base tree is considered to be that of the parent.

protected abstract TTreeNode InitializeNewNode(TTreeNode parentNode, TValue value = default)

Parameters

parentNode TTreeNode

The parent node.

value TValue

The value of the node.

Returns

TTreeNode

MakeChildOf(TTreeNode)

Makes this node a child of another tree node.

public void MakeChildOf(TTreeNode other)

Parameters

other TTreeNode

The other tree node that will become this node's parent.

MakeParentOf(TTreeNode)

Makes this node a parent of another tree node.

public void MakeParentOf(TTreeNode other)

Parameters

other TTreeNode

The other tree node that will become this node's child.

PerformChildRemoval(TTreeNode)

Performs the removal of a child.

protected abstract bool PerformChildRemoval(TTreeNode childToRemove)

Parameters

childToRemove TTreeNode

The child to remove from the children collection.

Returns

bool

true if the child was found and removed, otherwise false.

RegisterAddedChild(TTreeNode)

Performs the operations after a child was added to this tree.

protected abstract void RegisterAddedChild(TTreeNode addedChild)

Parameters

addedChild TTreeNode

The child that was added to the children collection.

RemoveChild(TValue)

Removes a child from this node's children list.

public bool RemoveChild(TValue childToRemove)

Parameters

childToRemove TValue

The child to remove from this node's children list.

Returns

bool

RemoveChild(TTreeNode)

Removes a child from this node's children list.

public bool RemoveChild(TTreeNode childToRemove)

Parameters

childToRemove TTreeNode

The child to remove from this node's children list.

Returns

bool

RemoveNode(TValue)

Removes a node that has the specified value. This includes any node that is within the subtree with this tree node as the root.

public virtual bool RemoveNode(TValue value)

Parameters

value TValue

The value of the node to remove from this node's children list.

Returns

bool

true if the child was successfully removed from this node's children list, otherwise false.

RemoveNode(TTreeNode)

Removes a node that has the specified value. This includes any node that is within the subtree with this tree node as the root.

public virtual bool RemoveNode(TTreeNode node)

Parameters

node TTreeNode

The node to remove from this node's children list.

Returns

bool

true if the child was successfully removed from this node's children list, otherwise false.

RemoveNodes(IEnumerable<TValue>)

Removes nodes that have the specified values. This includes any node that is within the subtree with this tree node as the root.

public virtual void RemoveNodes(IEnumerable<TValue> values)

Parameters

values IEnumerable<TValue>

The values of the child nodes to remove from this node's children list.

RemoveNodes(params TValue[])

Removes nodes that have the specified values. This includes any node that is within the subtree with this tree node as the root.

public void RemoveNodes(params TValue[] values)

Parameters

values TValue[]

The values of the child nodes to remove from this node's children list.

ToString()

Gets the string representation of this tree node's value.

public override string ToString()

Returns

string

The string representation of this tree node's value.

TraverseLevelOrder()

Traverses the subtree with this node as a root using level-order. The elements are returned with yield return.

public IEnumerable<TValue> TraverseLevelOrder()

Returns

IEnumerable<TValue>

The yielded values.

TraverseLevelOrderNodes()

Traverses the subtree with this node as a root using level-order. The nodes are returned with yield return.

public abstract IEnumerable<TTreeNode> TraverseLevelOrderNodes()

Returns

IEnumerable<TTreeNode>

The yielded nodes.

TraversePostOrder()

Traverses the subtree with this node as a root using post-order. The elements are returned with yield return.

public IEnumerable<TValue> TraversePostOrder()

Returns

IEnumerable<TValue>

The yielded values.

TraversePostOrderNodes()

Traverses the subtree with this node as a root using post-order. The nodes are returned with yield return.

public abstract IEnumerable<TTreeNode> TraversePostOrderNodes()

Returns

IEnumerable<TTreeNode>

The yielded nodes.

TraversePreOrder()

Traverses the subtree with this node as a root using pre-order. The elements are returned with yield return.

public IEnumerable<TValue> TraversePreOrder()

Returns

IEnumerable<TValue>

The yielded values.

TraversePreOrderNodes()

Traverses the subtree with this node as a root using pre-order. The nodes are returned with yield return.

public abstract IEnumerable<TTreeNode> TraversePreOrderNodes()

Returns

IEnumerable<TTreeNode>

The yielded nodes.