< Summary

Class:Towel.DataStructures.SortedBinaryTree
Assembly:Towel
File(s):File 1: /home/runner/work/Towel/Towel/Sources/Towel/DataStructures/SortedBinaryTree.cs
Covered lines:0
Uncovered lines:30
Coverable lines:30
Total lines:193
Line coverage:0% (0 of 30)
Covered branches:0
Total branches:14
Branch coverage:0% (0 of 14)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
File 1: ContainsSift(...)0%20%
File 1: TryGet(...)0%20%
File 1: TryRemoveSift(...)0%20%
File 1: Stepper(...)0%20%
File 1: Stepper(...)100%10%
File 1: StepperBreak(...)0%20%
File 1: StepperReverse(...)0%20%
File 1: StepperReverse(...)100%10%
File 1: StepperReverseBreak(...)0%20%

File(s)

/home/runner/work/Towel/Towel/Sources/Towel/DataStructures/SortedBinaryTree.cs

#LineLine coverage
 1namespace Towel.DataStructures;
 2
 3/// <summary>A self-sorting binary tree based on the heights of each node.</summary>
 4/// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 5public interface ISortedBinaryTree<T> : IDataStructure<T>,
 6  DataStructure.IAddable<T>,
 7  DataStructure.IRemovable<T>,
 8  DataStructure.ICountable,
 9  DataStructure.IClearable,
 10  DataStructure.IAuditable<T>
 11{
 12  #region Properties
 13
 14  /// <summary>Gets the current least value in the tree.</summary>
 15  T CurrentLeast { get; }
 16  /// <summary>Gets the current greated value in the tree.</summary>
 17  T CurrentGreatest { get; }
 18
 19  #endregion
 20
 21  #region Methods
 22
 23  /// <summary>Determines if the tree contains a value.</summary>
 24  /// <typeparam name="TSift">The type of the sifting function.</typeparam>
 25  /// <param name="sift">The sifting function that respects the sorting of the tree.</param>
 26  /// <returns>True if the value is in the tree or false if not.</returns>
 27  bool ContainsSift<TSift>(TSift sift = default)
 28    where TSift : struct, IFunc<T, CompareResult>;
 29
 30  /// <summary>Tries to get a value.</summary>
 31  /// <typeparam name="TSift">The type of the sifting function.</typeparam>
 32  /// <param name="sift">The sifting function that respects the sorting of the tree.</param>
 33  /// <returns>True if the value was found or false if not.</returns>
 34  (bool Success, T? Value, Exception? Exception) TryGet<TSift>(TSift sift = default)
 35    where TSift : struct, IFunc<T, CompareResult>;
 36
 37  /// <summary>Tries to remove a value.</summary>
 38  /// <typeparam name="TSift">The type of the sifting function.</typeparam>
 39  /// <param name="sift">The sifting function that respects the sorting of the tree.</param>
 40  /// <returns>True if the remove succeeded or false if not.</returns>
 41  (bool Success, Exception? Exception) TryRemoveSift<TSift>(TSift sift = default)
 42    where TSift : struct, IFunc<T, CompareResult>;
 43
 44  /// <summary>Does an optimized step function (left to right) for sorted binary search trees.</summary>
 45  /// <typeparam name="TStep">The type of the step function.</typeparam>
 46  /// <param name="minimum">The minimum step value.</param>
 47  /// <param name="maximum">The maximum step value.</param>
 48  /// <param name="step">The step function.</param>
 49  /// <returns>The result status of the stepper function.</returns>
 50  StepStatus StepperBreak<TStep>(T minimum, T maximum, TStep step = default)
 51    where TStep : struct, IFunc<T, StepStatus>;
 52
 53  /// <summary>Does a step function (right to left) for sorted binary search trees.</summary>
 54  /// <typeparam name="TStep">The type of the step function.</typeparam>
 55  /// <param name="step">The step function.</param>
 56  /// <returns>The result status of the stepper function.</returns>
 57  StepStatus StepperReverseBreak<TStep>(TStep step = default)
 58    where TStep : struct, IFunc<T, StepStatus>;
 59
 60  /// <summary>Does an optimized step function (right to left) for sorted binary search trees.</summary>
 61  /// <typeparam name="TStep">The type of the step function.</typeparam>
 62  /// <param name="minimum">The minimum step value.</param>
 63  /// <param name="maximum">The maximum step value.</param>
 64  /// <param name="step">The step function.</param>
 65  /// <returns>The result status of the stepper function.</returns>
 66  StepStatus StepperReverseBreak<TStep>(T minimum, T maximum, TStep step = default)
 67    where TStep : struct, IFunc<T, StepStatus>;
 68
 69  #endregion
 70}
 71
 72/// <summary>A self-sorting binary tree based on the heights of each node.</summary>
 73/// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 74/// <typeparam name="TCompare">The type that is comparing <typeparamref name="T"/> values.</typeparam>
 75public interface ISortedBinaryTree<T, TCompare> : ISortedBinaryTree<T>,
 76  DataStructure.IComparing<T, TCompare>
 77  where TCompare : struct, IFunc<T, T, CompareResult>
 78{
 79
 80}
 81
 82/// <summary>Static members for <see cref="ISortedBinaryTree{T}"/> and <see cref="ISortedBinaryTree{T, TCompare}"/>.</su
 83public static class SortedBinaryTree
 84{
 85  #region Extension Methods
 86
 87  /// <summary>Determines if the tree contains a value.</summary>
 88  /// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 89  /// <param name="tree">The tree to perfrom the contains check on.</param>
 90  /// <param name="sift">The sifting function that respects the sorting of the tree.</param>
 91  /// <returns>True if the value is in the tree or false if not.</returns>
 92  public static bool ContainsSift<T>(this ISortedBinaryTree<T> tree, Func<T, CompareResult> sift)
 093  {
 094    if (sift is null) throw new ArgumentNullException(nameof(sift));
 095    return tree.ContainsSift<SFunc<T, CompareResult>>(sift);
 096  }
 97
 98  /// <summary>Tries to get a value.</summary>
 99  /// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 100  /// <param name="tree">The tree to perfrom the TryGet on.</param>
 101  /// <param name="sift">The sifting function that respects the sorting of the tree.</param>
 102  /// <returns>True if the value was found or false if not.</returns>
 103  public static (bool Success, T? Value, Exception? Exception) TryGet<T>(this ISortedBinaryTree<T> tree, Func<T, Compare
 0104  {
 0105    if (sift is null) throw new ArgumentNullException(nameof(sift));
 0106    return tree.TryGet<SFunc<T, CompareResult>>(sift);
 0107  }
 108
 109  /// <summary>Tries to remove a value.</summary>
 110  /// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 111  /// <param name="tree">The tree to perfrom the TryRemoveSift on.</param>
 112  /// <param name="sift">The sifting function that respects the sorting of the tree.</param>
 113  /// <returns>True if the remove succeeded or false if not.</returns>
 114  public static (bool Success, Exception? Exception) TryRemoveSift<T>(this ISortedBinaryTree<T> tree, Func<T, CompareRes
 0115  {
 0116    if (sift is null) throw new ArgumentNullException(nameof(sift));
 0117    return tree.TryRemoveSift<SFunc<T, CompareResult>>(sift);
 0118  }
 119
 120  /// <summary>Does an optimized step function (left to right) for sorted binary search trees.</summary>
 121  /// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 122  /// <param name="tree">The tree to traverse.</param>
 123  /// <param name="minimum">The minimum step value.</param>
 124  /// <param name="maximum">The maximum step value.</param>
 125  /// <param name="step">The step function.</param>
 126  public static void Stepper<T>(this ISortedBinaryTree<T> tree, T minimum, T maximum, Action<T> step)
 0127  {
 0128    if (step is null) throw new ArgumentNullException(nameof(step));
 0129    tree.StepperBreak<StepBreakFromAction<T, SAction<T>>>(minimum, maximum, new SAction<T>() { Action = step });
 0130  }
 131
 132  /// <summary>Does an optimized step function (left to right) for sorted binary search trees.</summary>
 133  /// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 134  /// <typeparam name="TStep">The type of the step function.</typeparam>
 135  /// <param name="tree">The tree to traverse.</param>
 136  /// <param name="minimum">The minimum step value.</param>
 137  /// <param name="maximum">The maximum step value.</param>
 138  /// <param name="step">The step function.</param>
 139  public static void Stepper<T, TStep>(this ISortedBinaryTree<T> tree, T minimum, T maximum, TStep step = default)
 140    where TStep : struct, IAction<T> =>
 0141    tree.StepperBreak<StepBreakFromAction<T, TStep>>(minimum, maximum, step);
 142
 143  /// <summary>Does an optimized step function (left to right) for sorted binary search trees.</summary>
 144  /// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 145  /// <param name="tree">The tree to traverse.</param>
 146  /// <param name="minimum">The minimum step value.</param>
 147  /// <param name="maximum">The maximum step value.</param>
 148  /// <param name="step">The step function.</param>
 149  /// <returns>The result status of the stepper function.</returns>
 150  public static StepStatus StepperBreak<T>(this ISortedBinaryTree<T> tree, T minimum, T maximum, Func<T, StepStatus> ste
 0151  {
 0152    if (step is null) throw new ArgumentNullException(nameof(step));
 0153    return tree.StepperBreak<SFunc<T, StepStatus>>(minimum, maximum, step);
 0154  }
 155
 156  /// <summary>Does an optimized step function (right to left) for sorted binary search trees.</summary>
 157  /// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 158  /// <param name="tree">The tree to traverse.</param>
 159  /// <param name="minimum">The minimum step value.</param>
 160  /// <param name="maximum">The maximum step value.</param>
 161  /// <param name="step">The step function.</param>
 162  public static void StepperReverse<T>(this ISortedBinaryTree<T> tree, T minimum, T maximum, Action<T> step)
 0163  {
 0164    if (step is null) throw new ArgumentNullException(nameof(step));
 0165    tree.StepperReverseBreak<StepBreakFromAction<T, SAction<T>>>(minimum, maximum, new SAction<T>() { Action = step });
 0166  }
 167
 168  /// <summary>Does an optimized step function (right to left) for sorted binary search trees.</summary>
 169  /// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 170  /// <typeparam name="TStep">The type of the step function.</typeparam>
 171  /// <param name="tree">The tree to traverse.</param>
 172  /// <param name="minimum">The minimum step value.</param>
 173  /// <param name="maximum">The maximum step value.</param>
 174  /// <param name="step">The step function.</param>
 175  public static void StepperReverse<T, TStep>(this ISortedBinaryTree<T> tree, T minimum, T maximum, TStep step = default
 176    where TStep : struct, IAction<T> =>
 0177    tree.StepperReverseBreak<StepBreakFromAction<T, TStep>>(minimum, maximum, step);
 178
 179  /// <summary>Does an optimized step function (right to left) for sorted binary search trees.</summary>
 180  /// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 181  /// <param name="tree">The tree to traverse.</param>
 182  /// <param name="minimum">The minimum step value.</param>
 183  /// <param name="maximum">The maximum step value.</param>
 184  /// <param name="step">The step function.</param>
 185  /// <returns>The result status of the stepper function.</returns>
 186  public static StepStatus StepperReverseBreak<T>(this ISortedBinaryTree<T> tree, T minimum, T maximum, Func<T, StepStat
 0187  {
 0188    if (step is null) throw new ArgumentNullException(nameof(step));
 0189    return tree.StepperReverseBreak<SFunc<T, StepStatus>>(minimum, maximum, step);
 0190  }
 191
 192  #endregion
 193}