MCPcopy Create free account
hub / github.com/coreutils/coreutils / heapify_down

Function heapify_down

gl/lib/heap.c:110–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108/* Move element down into appropriate position in heap. */
109
110static void
111heapify_down (void **array, idx_t count, idx_t initial,
112 int (*compare) (void const *, void const *))
113{
114 void *element = array[initial];
115
116 idx_t parent = initial;
117 while (parent <= count >> 1)
118 {
119 idx_t child = 2 * parent;
120
121 if (child < count && compare (array[child], array[child + 1]) < 0)
122 child++;
123
124 if (compare (array[child], element) <= 0)
125 break;
126
127 array[parent] = array[child];
128 parent = child;
129 }
130
131 array[parent] = element;
132}
133
134/* Move element up into appropriate position in heap. */
135

Callers 1

heap_remove_topFunction · 0.85

Calls 1

compareFunction · 0.85

Tested by

no test coverage detected