121 pg_fatal(
"out of binary heap slots");
159 pg_fatal(
"out of binary heap slots");
230 Assert(n >= 0 && n < heap->bh_size);
279 while (node_off != 0)
290 parent_val = heap->
bh_nodes[parent_off];
301 heap->
bh_nodes[node_off] = parent_val;
302 node_off = parent_off;
305 heap->
bh_nodes[node_off] = node_val;
326 int swap_off = left_off;
329 if (right_off < heap->bh_size &&
333 swap_off = right_off;
339 if (left_off >= heap->
bh_size ||
353 heap->
bh_nodes[node_off] = node_val;
void binaryheap_remove_node(binaryheap *heap, int n)
void binaryheap_build(binaryheap *heap)
void binaryheap_replace_first(binaryheap *heap, bh_node_type d)
void binaryheap_reset(binaryheap *heap)
bh_node_type binaryheap_first(binaryheap *heap)
void binaryheap_add(binaryheap *heap, bh_node_type d)
bh_node_type binaryheap_remove_first(binaryheap *heap)
static void sift_down(binaryheap *heap, int node_off)
static int parent_offset(int i)
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
static void sift_up(binaryheap *heap, int node_off)
static int right_offset(int i)
static int left_offset(int i)
void binaryheap_free(binaryheap *heap)
void binaryheap_add_unordered(binaryheap *heap, bh_node_type d)
#define binaryheap_empty(h)
int(* binaryheap_comparator)(bh_node_type a, bh_node_type b, void *arg)
#define Assert(condition)
static int compare(const void *arg1, const void *arg2)
void pfree(void *pointer)
static int cmp(const chr *x, const chr *y, size_t len)
bool bh_has_heap_property
binaryheap_comparator bh_compare
bh_node_type bh_nodes[FLEXIBLE_ARRAY_MEMBER]