Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Runtime/UnsafeMinPriorityQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ public void EnqueueRange(ReadOnlySpan<T> elements)
{
nodes.AddRangeNoResize(ptr, elements.Length);
}
if (Count > 1)
{
Heapify();
}
Heapify();
}
else
{
Expand Down Expand Up @@ -180,7 +177,7 @@ private void RemoveRootNode()
/// Gets the index of an element's parent.
/// </summary>
[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;

/// <summary>
/// Gets the index of the first child of an element.
Expand All @@ -192,6 +189,11 @@ private void RemoveRootNode()
/// </summary>
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.
Expand Down
Loading