MCPcopy Create free account
hub / github.com/apache/cloudberry / binaryheap_remove_first

Function binaryheap_remove_first

src/backend/lib/binaryheap.c:173–194  ·  view source on GitHub ↗

* binaryheap_remove_first * * Removes the first (root, topmost) node in the heap and returns a * pointer to it after rebalancing the heap. The caller must ensure * that this routine is not used on an empty heap. O(log n) worst * case. */

Source from the content-addressed store, hash-verified

171 * case.
172 */
173Datum
174binaryheap_remove_first(binaryheap *heap)
175{
176 Assert(!binaryheap_empty(heap) && heap->bh_has_heap_property);
177
178 if (heap->bh_size == 1)
179 {
180 heap->bh_size--;
181 return heap->bh_nodes[0];
182 }
183
184 /*
185 * Swap the root and last nodes, decrease the size of the heap (i.e.
186 * remove the former root node) and sift the new root node down to its
187 * correct position.
188 */
189 swap_nodes(heap, 0, heap->bh_size - 1);
190 heap->bh_size--;
191 sift_down(heap, 0);
192
193 return heap->bh_nodes[heap->bh_size];
194}
195
196/*
197 * binaryheap_replace_first

Callers 7

ReorderBufferIterTXNNextFunction · 0.85
BufferSyncFunction · 0.85
pgarch_readyXlogFunction · 0.85
execMotionSortedReceiverFunction · 0.85
ExecMergeAppendFunction · 0.85
gather_merge_getnextFunction · 0.85

Calls 2

sift_downFunction · 0.85
swap_nodesFunction · 0.70

Tested by

no test coverage detected