Add tests and make minor fixes to PriorityQueue.

This commit is contained in:
RoosterDragon
2016-02-26 22:41:14 +00:00
parent 86e4a72dce
commit 0306a8de6c
3 changed files with 57 additions and 6 deletions

View File

@@ -76,17 +76,19 @@ namespace OpenRA.Primitives
return At(lastLevel, lastIndex);
}
public T Peek() { return At(0, 0); }
public T Peek()
{
if (level <= 0 && index <= 0)
throw new InvalidOperationException("PriorityQueue empty.");
return At(0, 0);
}
public T Pop()
{
if (level == 0 && index == 0)
throw new InvalidOperationException("Attempting to pop empty PriorityQueue");
var ret = At(0, 0);
var ret = Peek();
BubbleInto(0, 0, Last());
if (--index < 0)
index = (1 << --level) - 1;
return ret;
}