Class SizedBinaryTreeMethodsBase<TElement>
- Namespace
- Platform.Collections.Methods.Trees
- Assembly
- Platform.Collections.Methods.dll
Represents the sized binary tree methods base.
public abstract class SizedBinaryTreeMethodsBase<TElement> where TElement : IUnsignedNumber<TElement>, IComparisonOperators<TElement, TElement, bool>
Type Parameters
TElement
- Inheritance
-
SizedBinaryTreeMethodsBase<TElement>
- Derived
- Inherited Members
Methods
AfterAttach()
protected virtual void AfterAttach()
Attach(ref TElement, TElement)
Attaches the root.
public void Attach(ref TElement root, TElement node)
Parameters
rootTElementThe root.
nodeTElementThe node.
AttachCore(ref TElement, TElement)
Attaches the core using the specified root.
protected abstract void AttachCore(ref TElement root, TElement node)
Parameters
rootTElementThe root.
nodeTElementThe node.
BeforeAttach()
protected virtual void BeforeAttach()
ClearNode(TElement)
Clears the node using the specified node.
protected virtual void ClearNode(TElement node)
Parameters
nodeTElementThe node.
Contains(TElement, TElement)
Determines whether this instance contains.
public virtual bool Contains(TElement node, TElement root)
Parameters
nodeTElementThe node.
rootTElementThe root.
Returns
- bool
The bool
DecrementSize(TElement)
Decrements the size using the specified node.
protected void DecrementSize(TElement node)
Parameters
nodeTElementThe node.
Detach(ref TElement, TElement)
Detaches the root.
public void Detach(ref TElement root, TElement node)
Parameters
rootTElementThe root.
nodeTElementThe node.
DetachCore(ref TElement, TElement)
Detaches the core using the specified root.
protected abstract void DetachCore(ref TElement root, TElement node)
Parameters
rootTElementThe root.
nodeTElementThe node.
FirstIsToTheLeftOfSecond(TElement, TElement)
Determines whether this instance first is to the left of second.
protected abstract bool FirstIsToTheLeftOfSecond(TElement first, TElement second)
Parameters
firstTElementThe first.
secondTElementThe second.
Returns
- bool
The bool
FirstIsToTheRightOfSecond(TElement, TElement)
Determines whether this instance first is to the right of second.
protected abstract bool FirstIsToTheRightOfSecond(TElement first, TElement second)
Parameters
firstTElementThe first.
secondTElementThe second.
Returns
- bool
The bool
FixSize(TElement)
Fixes the size using the specified node.
protected void FixSize(TElement node)
Parameters
nodeTElementThe node.
FixSizes(TElement)
Fixes the sizes using the specified node.
public void FixSizes(TElement node)
Parameters
nodeTElementThe node.
GetLeft(TElement)
Gets the left using the specified node.
protected abstract TElement GetLeft(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The element
GetLeftOrDefault(TElement)
Gets the left or default using the specified node.
protected virtual TElement GetLeftOrDefault(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The element
GetLeftReference(TElement)
Gets the left reference using the specified node.
protected abstract ref TElement GetLeftReference(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The ref element
GetLeftSize(TElement)
Gets the left size using the specified node.
protected TElement GetLeftSize(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The element
GetLeftest(TElement)
Gets the leftest using the specified current.
protected virtual TElement GetLeftest(TElement current)
Parameters
currentTElementThe current.
Returns
- TElement
The current.
GetMaximumBalancedHeight(TElement)
Returns the largest number of levels that a size balanced tree or an AVL tree with the specified number of nodes can have.
Возвращает наибольшее число уровней, которое может иметь дерево, сбалансированное по размеру, или АВЛ-дерево с указанным числом узлов.
public static int GetMaximumBalancedHeight(TElement size)
Parameters
sizeTElementThe number of nodes.
Число узлов.
Returns
- int
The largest height, about
1.44 · log2(size).Наибольшая высота, примерно
1.44 · log2(size).
Remarks
The sparsest tree of either kind with h levels has m(h) = m(h - 1) + m(h - 2) + 1 nodes, where m(0) = 0 and m(1) = 1.
Самое разреженное дерево любого из этих видов с h уровнями имеет m(h) = m(h - 1) + m(h - 2) + 1 узлов, где m(0) = 0 и m(1) = 1.
GetNext(TElement)
Gets the next using the specified node.
protected virtual TElement GetNext(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The element
GetPrevious(TElement)
Gets the previous using the specified node.
protected virtual TElement GetPrevious(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The element
GetRight(TElement)
Gets the right using the specified node.
protected abstract TElement GetRight(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The element
GetRightOrDefault(TElement)
Gets the right or default using the specified node.
protected virtual TElement GetRightOrDefault(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The element
GetRightReference(TElement)
Gets the right reference using the specified node.
protected abstract ref TElement GetRightReference(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The ref element
GetRightSize(TElement)
Gets the right size using the specified node.
protected TElement GetRightSize(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The element
GetRightest(TElement)
Gets the rightest using the specified current.
protected virtual TElement GetRightest(TElement current)
Parameters
currentTElementThe current.
Returns
- TElement
The current.
GetSize(TElement)
Gets the size using the specified node.
protected abstract TElement GetSize(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The element
GetSizeOrZero(TElement)
Gets the size or zero using the specified node.
protected TElement GetSizeOrZero(TElement node)
Parameters
nodeTElementThe node.
Returns
- TElement
The element
IncrementSize(TElement)
Increments the size using the specified node.
protected void IncrementSize(TElement node)
Parameters
nodeTElementThe node.
LeftRotate(TElement)
Lefts the rotate using the specified root.
protected TElement LeftRotate(TElement root)
Parameters
rootTElementThe root.
Returns
- TElement
The right.
LeftRotate(ref TElement)
Lefts the rotate using the specified root.
protected void LeftRotate(ref TElement root)
Parameters
rootTElementThe root.
PrintNode(TElement)
Prints the node using the specified node.
public string PrintNode(TElement node)
Parameters
nodeTElementThe node.
Returns
- string
The string
PrintNode(TElement, StringBuilder)
Prints the node using the specified node.
protected void PrintNode(TElement node, StringBuilder sb)
Parameters
nodeTElementThe node.
sbStringBuilderThe string builder.
PrintNode(TElement, StringBuilder, int)
Prints the node using the specified node.
protected virtual void PrintNode(TElement node, StringBuilder sb, int level)
Parameters
nodeTElementThe node.
sbStringBuilderThe string builder.
levelintThe level.
PrintNodeValue(TElement, StringBuilder)
Prints the node value using the specified node.
protected abstract void PrintNodeValue(TElement node, StringBuilder sb)
Parameters
nodeTElementThe node.
sbStringBuilderThe string builder.
PrintNodes(TElement)
Prints the nodes using the specified node.
public string PrintNodes(TElement node)
Parameters
nodeTElementThe node.
Returns
- string
The string
PrintNodes(TElement, StringBuilder)
Prints the nodes using the specified node.
public void PrintNodes(TElement node, StringBuilder sb)
Parameters
nodeTElementThe node.
sbStringBuilderThe string builder.
PrintNodes(TElement, StringBuilder, int)
Prints the nodes using the specified node.
public void PrintNodes(TElement node, StringBuilder sb, int level)
Parameters
nodeTElementThe node.
sbStringBuilderThe string builder.
levelintThe level.
RebuildComplete(TElement)
Rebuilds the subtree into a complete binary tree with rotations only (Day–Stout–Warren), in linear time and without extra memory.
Перестраивает поддерево в полное двоичное дерево только поворотами (Дэй–Стаут–Уоррен) за линейное время и без дополнительной памяти.
protected TElement RebuildComplete(TElement root)
Parameters
rootTElementThe root of the subtree.
Корень поддерева.
Returns
- TElement
The new root of the subtree.
Новый корень поддерева.
Remarks
The last level is filled from the left, so the result is also a size balanced tree. Only for trees whose nodes keep just the left child, the right child and the size (not for threaded trees).
Последний уровень заполняется слева, поэтому результат также является деревом, сбалансированным по размеру. Только для деревьев, узлы которых хранят лишь левого потомка, правого потомка и размер (не для прошитых деревьев).
RightRotate(TElement)
Rights the rotate using the specified root.
protected TElement RightRotate(TElement root)
Parameters
rootTElementThe root.
Returns
- TElement
The left.
RightRotate(ref TElement)
Rights the rotate using the specified root.
protected void RightRotate(ref TElement root)
Parameters
rootTElementThe root.
SetLeft(TElement, TElement)
Sets the left using the specified node.
protected abstract void SetLeft(TElement node, TElement left)
Parameters
nodeTElementThe node.
leftTElementThe left.
SetRight(TElement, TElement)
Sets the right using the specified node.
protected abstract void SetRight(TElement node, TElement right)
Parameters
nodeTElementThe node.
rightTElementThe right.
SetSize(TElement, TElement)
Sets the size using the specified node.
protected abstract void SetSize(TElement node, TElement size)
Parameters
nodeTElementThe node.
sizeTElementThe size.
ValidateSize(TElement)
Validates the size using the specified node.
public void ValidateSize(TElement node)
Parameters
nodeTElementThe node.
Exceptions
- InvalidOperationException
Size of {node} is not valid. Expected size: {expectedSize}, actual size: {size}.
ValidateSizes(TElement)
Validates the sizes using the specified node.
public void ValidateSizes(TElement node)
Parameters
nodeTElementThe node.
Exceptions
- InvalidOperationException
Size of {node} is not valid. Expected size: {expectedSize}, actual size: {size}.