diff --git a/Source/Collections/PairPriorityQueue.cs b/Source/Collections/PairPriorityQueue.cs
index c3f316b..1b05ffa 100644
--- a/Source/Collections/PairPriorityQueue.cs
+++ b/Source/Collections/PairPriorityQueue.cs
@@ -73,6 +73,12 @@ namespace Nuclex.Support.Collections {
);
}
+ /// Returns the topmost item in the queue without dequeueing it
+ /// The topmost item in the queue
+ public PriorityItemPair Peek() {
+ return this.internalQueue.Peek();
+ }
+
/// Takes the item with the highest priority off from the queue
/// The item with the highest priority in the list
public PriorityItemPair Dequeue() {
diff --git a/Source/Collections/PriorityQueue.cs b/Source/Collections/PriorityQueue.cs
index 934d12e..ca3706c 100644
--- a/Source/Collections/PriorityQueue.cs
+++ b/Source/Collections/PriorityQueue.cs
@@ -107,12 +107,23 @@ namespace Nuclex.Support.Collections {
this.heap = new ItemType[this.capacity];
}
+ /// Returns the topmost item in the queue without dequeueing it
+ /// The topmost item in the queue
+ public ItemType Peek() {
+ if(this.count == 0) {
+ throw new InvalidOperationException("No items queued");
+ }
+
+ return this.heap[0];
+ }
+
/// Takes the item with the highest priority off from the queue
/// The item with the highest priority in the list
/// When the queue is empty
public ItemType Dequeue() {
- if(count == 0)
+ if(this.count == 0) {
throw new InvalidOperationException("No items available to dequeue");
+ }
ItemType result = this.heap[0];
--this.count;
@@ -150,7 +161,7 @@ namespace Nuclex.Support.Collections {
/// Array to copy the priority queue into
/// Starting index for the destination array
public void CopyTo(Array array, int index) {
- Array.Copy(heap, 0, array, index, this.count);
+ Array.Copy(this.heap, 0, array, index, this.count);
}
///