Skip to content

Commit

Permalink
🥈 Allow enumeration of priority queues (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcscharf authored May 31, 2021
1 parent f9a2118 commit 9196603
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Bearded.Utilities/Collections/StaticPriorityQueue.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -9,7 +10,9 @@ namespace Bearded.Utilities.Collections
/// </summary>
/// <typeparam name="TPriority"></typeparam>
/// <typeparam name="TValue"></typeparam>
public class StaticPriorityQueue<TPriority, TValue> where TPriority : IComparable<TPriority>
public class StaticPriorityQueue<TPriority, TValue>
: IEnumerable<KeyValuePair<TPriority, TValue>>
where TPriority : IComparable<TPriority>
{
/// <summary>
/// Array-representation of the entire heap.
Expand Down Expand Up @@ -203,5 +206,15 @@ private static int getRightChild(int i)
return 2 * i + 2;
}
#endregion

public IEnumerator<KeyValuePair<TPriority, TValue>> GetEnumerator()
{
for (var i = 0; i < Count; i++)
{
yield return data[i];
}
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}

0 comments on commit 9196603

Please sign in to comment.