File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -145,10 +145,7 @@ public void EnqueueRange(ReadOnlySpan<T> elements)
145145 {
146146 nodes . AddRangeNoResize ( ptr , elements . Length ) ;
147147 }
148- if ( Count > 1 )
149- {
150- Heapify ( ) ;
151- }
148+ Heapify ( ) ;
152149 }
153150 else
154151 {
@@ -180,7 +177,7 @@ private void RemoveRootNode()
180177 /// Gets the index of an element's parent.
181178 /// </summary>
182179 [ return : AssumeRange ( 0 , ( int . MaxValue - 1 ) >> Log2Arity ) ]
183- private static int GetParentIndex ( int index ) => ( index - 1 ) >> Log2Arity ;
180+ private static int GetParentIndex ( [ AssumeRange ( 1 , int . MaxValue ) ] int index ) => ( index - 1 ) >> Log2Arity ;
184181
185182 /// <summary>
186183 /// Gets the index of the first child of an element.
@@ -192,6 +189,11 @@ private void RemoveRootNode()
192189 /// </summary>
193190 internal void Heapify ( )
194191 {
192+ if ( nodes . Length <= 1 )
193+ {
194+ return ;
195+ }
196+
195197 // Leaves of the tree are in fact 1-element heaps, for which there
196198 // is no need to correct them. The heap property needs to be restored
197199 // only for higher nodes, starting from the first node that has children.
You can’t perform that action at this time.
0 commit comments