Skip to content

Commit

Permalink
Queue Stepper Updates #37
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyPatten committed Mar 1, 2020
1 parent b36c7dc commit 5aff33a
Show file tree
Hide file tree
Showing 7 changed files with 459 additions and 145 deletions.
8 changes: 4 additions & 4 deletions Sources/Towel/DataStructures/Heap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,21 @@ public IEnumerator<T> GetEnumerator()

/// <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(Step<T> step) => _heap.Stepper(step, 1, _count + 1);
public void Stepper(Step<T> step) => _heap.Stepper(1, _count + 1, 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) => _heap.Stepper(step, 1, _count + 1);
public void Stepper(StepRef<T> step) => _heap.Stepper(1, _count + 1, 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(StepBreak<T> step) => _heap.Stepper(step, 1, _count + 1);
public StepStatus Stepper(StepBreak<T> step) => _heap.Stepper(1, _count + 1, 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) => _heap.Stepper(step, 1, _count + 1);
public StepStatus Stepper(StepRefBreak<T> step) => _heap.Stepper(1, _count + 1, step);

/// <summary>Creates a shallow clone of this data structure.</summary>
/// <returns>A shallow clone of this data structure.</returns>
Expand Down
8 changes: 4 additions & 4 deletions Sources/Towel/DataStructures/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -741,21 +741,21 @@ public bool TryRemoveFirst<Predicate>(out Exception exception, Predicate predica

/// <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(Step<T> step) => _list.Stepper(step, 0, _count);
public void Stepper(Step<T> step) => _list.Stepper(0, _count, 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(step, 0, _count);
public void Stepper(StepRef<T> step) => _list.Stepper(0, _count, 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(StepBreak<T> step) => _list.Stepper(step, 0, _count);
public StepStatus Stepper(StepBreak<T> step) => _list.Stepper(0, _count, 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(step, 0, _count);
public StepStatus Stepper(StepRefBreak<T> step) => _list.Stepper(0, _count, step);

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

Expand Down
142 changes: 106 additions & 36 deletions Sources/Towel/DataStructures/Queue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,58 +210,79 @@ public void Clear()

#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 current = _head; !(current is null); current = current.Next)
{
step(current.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 current = _head; !(current is null); current = current.Next)
{
step(ref current.Value);
}
}
/// <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 current = _head; !(current is null); current = current.Next)
{
if (step(current.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>
/// <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>
/// <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(StepRefBreak<T> step)
/// <runtime>O(n * step)</runtime>
public StepStatus StepperRefBreak<Step>(Step step = default)
where Step : struct, IStepRefBreak<T>
{
for (Node current = _head; !(current is null); current = current.Next)
{
if (step(ref current.Value) is Break)
if (step.Do(ref current.Value) is Break)
{
return Break;
}
}
return Continue;
}

/// <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);

#endregion

#region IEnumerable

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

/// <summary>Gets the enumerator for this queue.</summary>
Expand Down Expand Up @@ -512,27 +533,78 @@ public void Clear()

#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>
/// <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>
/// <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>
public void Stepper(Step<T> step) => _queue.Stepper(step, 0, _count);
/// <returns>The resulting status of the iteration.</returns>
/// <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>
public void Stepper(StepRef<T> step) => _queue.Stepper(step, 0, _count);
/// <returns>The resulting status of the iteration.</returns>
/// <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>
/// <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) => _queue.Stepper(step, 0, _count);
/// <runtime>O(n * step)</runtime>
public StepStatus StepperRefBreak<Step>(Step step = default)
where Step : struct, IStepRefBreak<T>
{
for (int i = 0, index = _start; i < _count; i++, index++)
{
if (index == _queue.Length)
{
index = 0;
}
if (step.Do(ref _queue[index]) is Break)
{
return Break;
}
}
return Continue;
}

/// <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) => _queue.Stepper(step, 0, _count);
/// <runtime>O(n * step)</runtime>
public StepStatus Stepper(StepRefBreak<T> step) => StepperRefBreak<StepRefBreakRuntime<T>>(step);

#endregion

Expand All @@ -553,7 +625,5 @@ public System.Collections.Generic.IEnumerator<T> GetEnumerator()
#endregion

#endregion

#endregion
}
}
8 changes: 4 additions & 4 deletions Sources/Towel/DataStructures/Stack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,21 +445,21 @@ public void Clear()

/// <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(Step<T> step) => _array.Stepper(step, 0, _count);
public void Stepper(Step<T> step) => _array.Stepper(0, _count, 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) => _array.Stepper(step, 0, _count);
public void Stepper(StepRef<T> step) => _array.Stepper(0, _count, 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(StepBreak<T> step) => _array.Stepper(step, 0, _count);
public StepStatus Stepper(StepBreak<T> step) => _array.Stepper(0, _count, 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) => _array.Stepper(step, 0, _count);
public StepStatus Stepper(StepRefBreak<T> step) => _array.Stepper(0, _count, step);

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

Expand Down

0 comments on commit 5aff33a

Please sign in to comment.