Skip to content

Commit

Permalink
Added Compile Time Delegates To List #37
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyPatten committed Mar 2, 2020
1 parent 6e7de04 commit d91ab92
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 35 deletions.
133 changes: 98 additions & 35 deletions Sources/Towel/DataStructures/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,54 +333,69 @@ public bool TryRemoveFirst<Predicate>(out Exception exception, Predicate predica

#endregion

#region Stepper And IEnumerable
#region Stepper

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
public void Stepper(Step<T> step)
{
for (Node node = _head; !(node is null); node = node.Next)
{
step(node.Value);
}
}
/// <runtime>O(n * step)</runtime>
public void Stepper<Step>(Step step = default)
where Step : struct, IStep<T> =>
StepperRef<StepToStepRef<T, Step>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
public void Stepper(StepRef<T> step)
{
for (Node node = _head; !(node is null); node = node.Next)
{
T temp = node.Value;
step(ref temp);
node.Value = temp;
}
}
/// <runtime>O(n * step)</runtime>
public void Stepper(Step<T> step) =>
Stepper<StepRuntime<T>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <runtime>O(n * step)</runtime>
public void StepperRef<Step>(Step step = default)
where Step : struct, IStepRef<T> =>
StepperRefBreak<StepRefBreakFromStepRef<T, Step>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <runtime>O(n * step)</runtime>
public void Stepper(StepRef<T> step) =>
StepperRef<StepRefRuntime<T>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <returns>The resulting status of the iteration.</returns>
public StepStatus Stepper(StepBreak<T> step)
{
for (Node node = _head; !(node is null); node = node.Next)
{
if (step(node.Value) is Break)
{
return Break;
}
}
return Continue;
}
/// <runtime>O(n * step)</runtime>
public StepStatus StepperBreak<Step>(Step step = default)
where Step : struct, IStepBreak<T> =>
StepperRefBreak<StepRefBreakFromStepBreak<T, Step>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <returns>The resulting status of the iteration.</returns>
public StepStatus Stepper(StepRefBreak<T> step)
/// <runtime>O(n * step)</runtime>
public StepStatus Stepper(StepBreak<T> step) => StepperBreak<StepBreakRuntime<T>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <returns>The resulting status of the iteration.</returns>
/// <runtime>O(n * step)</runtime>
public StepStatus Stepper(StepRefBreak<T> step) => StepperRefBreak<StepRefBreakRuntime<T>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <returns>The resulting status of the iteration.</returns>
/// <runtime>O(n * step)</runtime>
public StepStatus StepperRefBreak<Step>(Step step = default)
where Step : struct, IStepRefBreak<T>
{
for (Node node = _head; !(node is null); node = node.Next)
{
T temp = node.Value;
if (step(ref temp) is Break)
if (step.Do(ref temp) is Break)
{
node.Value = temp;
return Break;
Expand All @@ -390,6 +405,10 @@ public StepStatus Stepper(StepRefBreak<T> step)
return Continue;
}

#endregion

#region IEnumerable

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();

/// <summary>Gets the enumerator for this list.</summary>
Expand Down Expand Up @@ -737,25 +756,69 @@ public bool TryRemoveFirst<Predicate>(out Exception exception, Predicate predica

#endregion

#region Stepper And IEnumerable
#region Stepper

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
public void Stepper(Step<T> step) => _list.Stepper(0, _count, step);
/// <runtime>O(n * step)</runtime>
public void Stepper<Step>(Step step = default)
where Step : struct, IStep<T> =>
StepperRef<StepToStepRef<T, Step>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
public void Stepper(StepRef<T> step) => _list.Stepper(0, _count, step);
/// <runtime>O(n * step)</runtime>
public void Stepper(Step<T> step) =>
Stepper<StepRuntime<T>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <runtime>O(n * step)</runtime>
public void StepperRef<Step>(Step step = default)
where Step : struct, IStepRef<T> =>
StepperRefBreak<StepRefBreakFromStepRef<T, Step>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <runtime>O(n * step)</runtime>
public void Stepper(StepRef<T> step) =>
StepperRef<StepRefRuntime<T>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <returns>The resulting status of the iteration.</returns>
public StepStatus Stepper(StepBreak<T> step) => _list.Stepper(0, _count, step);
/// <runtime>O(n * step)</runtime>
public StepStatus StepperBreak<Step>(Step step = default)
where Step : struct, IStepBreak<T> =>
StepperRefBreak<StepRefBreakFromStepBreak<T, Step>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <returns>The resulting status of the iteration.</returns>
public StepStatus Stepper(StepRefBreak<T> step) => _list.Stepper(0, _count, step);
/// <runtime>O(n * step)</runtime>
public StepStatus Stepper(StepBreak<T> step) => StepperBreak<StepBreakRuntime<T>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <returns>The resulting status of the iteration.</returns>
/// <runtime>O(n * step)</runtime>
public StepStatus Stepper(StepRefBreak<T> step) => StepperRefBreak<StepRefBreakRuntime<T>>(step);

/// <summary>Invokes a delegate for each entry in the data structure.</summary>
/// <typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
/// <param name="step">The delegate to invoke on each item in the structure.</param>
/// <returns>The resulting status of the iteration.</returns>
/// <runtime>O(n * step)</runtime>
public StepStatus StepperRefBreak<Step>(Step step = default)
where Step : struct, IStepRefBreak<T> =>
_list.StepperRefBreak(0, _count, step);

#endregion

#region IEnumerable

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();

Expand Down
60 changes: 60 additions & 0 deletions Sources/Towel/Towel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2597,23 +2597,53 @@
<param name="predicate">The predicate to determine removal.</param>
<returns>True if the value was removed. False if the value did not exist.</returns>
</member>
<member name="M:Towel.DataStructures.ListLinked`1.Stepper``1(``0)">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
<param name="step">The delegate to invoke on each item in the structure.</param>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListLinked`1.Stepper(Towel.Step{`0})">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<param name="step">The delegate to invoke on each item in the structure.</param>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListLinked`1.StepperRef``1(``0)">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
<param name="step">The delegate to invoke on each item in the structure.</param>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListLinked`1.Stepper(Towel.StepRef{`0})">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<param name="step">The delegate to invoke on each item in the structure.</param>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListLinked`1.StepperBreak``1(``0)">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
<param name="step">The delegate to invoke on each item in the structure.</param>
<returns>The resulting status of the iteration.</returns>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListLinked`1.Stepper(Towel.StepBreak{`0})">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<param name="step">The delegate to invoke on each item in the structure.</param>
<returns>The resulting status of the iteration.</returns>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListLinked`1.Stepper(Towel.StepRefBreak{`0})">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<param name="step">The delegate to invoke on each item in the structure.</param>
<returns>The resulting status of the iteration.</returns>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListLinked`1.StepperRefBreak``1(``0)">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
<param name="step">The delegate to invoke on each item in the structure.</param>
<returns>The resulting status of the iteration.</returns>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListLinked`1.GetEnumerator">
<summary>Gets the enumerator for this list.</summary>
Expand Down Expand Up @@ -2723,23 +2753,53 @@
<param name="predicate">The predicate to determine removal.</param>
<returns>True if the value was removed. False if the value did not exist.</returns>
</member>
<member name="M:Towel.DataStructures.ListArray`1.Stepper``1(``0)">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
<param name="step">The delegate to invoke on each item in the structure.</param>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListArray`1.Stepper(Towel.Step{`0})">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<param name="step">The delegate to invoke on each item in the structure.</param>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListArray`1.StepperRef``1(``0)">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
<param name="step">The delegate to invoke on each item in the structure.</param>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListArray`1.Stepper(Towel.StepRef{`0})">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<param name="step">The delegate to invoke on each item in the structure.</param>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListArray`1.StepperBreak``1(``0)">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
<param name="step">The delegate to invoke on each item in the structure.</param>
<returns>The resulting status of the iteration.</returns>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListArray`1.Stepper(Towel.StepBreak{`0})">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<param name="step">The delegate to invoke on each item in the structure.</param>
<returns>The resulting status of the iteration.</returns>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListArray`1.Stepper(Towel.StepRefBreak{`0})">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<param name="step">The delegate to invoke on each item in the structure.</param>
<returns>The resulting status of the iteration.</returns>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListArray`1.StepperRefBreak``1(``0)">
<summary>Invokes a delegate for each entry in the data structure.</summary>
<typeparam name="Step">The delegate to invoke on each item in the structure.</typeparam>
<param name="step">The delegate to invoke on each item in the structure.</param>
<returns>The resulting status of the iteration.</returns>
<runtime>O(n * step)</runtime>
</member>
<member name="M:Towel.DataStructures.ListArray`1.GetEnumerator">
<summary>Gets the enumerator for the data structure.</summary>
Expand Down

0 comments on commit d91ab92

Please sign in to comment.