From 1210901db25d030a506f7cc64905b2133b561cff Mon Sep 17 00:00:00 2001 From: "Ram.Type-0" Date: Sat, 27 Dec 2025 01:56:21 +0900 Subject: [PATCH 1/2] fix: Exception thrown when heapify empty queue (#32) --- Runtime/UnsafeMinPriorityQueue.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Runtime/UnsafeMinPriorityQueue.cs b/Runtime/UnsafeMinPriorityQueue.cs index b67252b..d072656 100644 --- a/Runtime/UnsafeMinPriorityQueue.cs +++ b/Runtime/UnsafeMinPriorityQueue.cs @@ -145,10 +145,7 @@ public void EnqueueRange(ReadOnlySpan elements) { nodes.AddRangeNoResize(ptr, elements.Length); } - if (Count > 1) - { - Heapify(); - } + Heapify(); } else { @@ -180,7 +177,7 @@ private void RemoveRootNode() /// Gets the index of an element's parent. /// [return: AssumeRange(0, (int.MaxValue - 1) >> Log2Arity)] - private static int GetParentIndex(int index) => (index - 1) >> Log2Arity; + private static int GetParentIndex([AssumeRange(1, int.MaxValue)] int index) => (index - 1) >> Log2Arity; /// /// Gets the index of the first child of an element. @@ -192,6 +189,11 @@ private void RemoveRootNode() /// internal void Heapify() { + if(nodes.Length <= 1) + { + return; + } + // Leaves of the tree are in fact 1-element heaps, for which there // is no need to correct them. The heap property needs to be restored // only for higher nodes, starting from the first node that has children. From 5d7c7b7c354bf743bf80d8549b1bfe3366826f5e Mon Sep 17 00:00:00 2001 From: "Ram.Type-0" <39725073+RamType0@users.noreply.github.com> Date: Sat, 27 Dec 2025 02:00:17 +0900 Subject: [PATCH 2/2] fix: Missing space after 'if' keyword Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Runtime/UnsafeMinPriorityQueue.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/UnsafeMinPriorityQueue.cs b/Runtime/UnsafeMinPriorityQueue.cs index d072656..30fbb13 100644 --- a/Runtime/UnsafeMinPriorityQueue.cs +++ b/Runtime/UnsafeMinPriorityQueue.cs @@ -189,7 +189,7 @@ private void RemoveRootNode() /// internal void Heapify() { - if(nodes.Length <= 1) + if (nodes.Length <= 1) { return; }