pheap.h
Go to the documentation of this file.
1 #pragma once
2 
25 
26 #include <stdlib.h>
27 #include <stdbool.h>
28 #include <unistd.h>
29 
30 #include <crater/container.h>
31 #include <crater/prand.h>
32 
33 typedef struct cr8r_pheap_node cr8r_pheap_node;
41 };
42 
48 typedef struct{
59  int (*cmp)(const cr8r_base_ft*, const void*, const void*);
65  void *(*alloc)(cr8r_base_ft*);
67  void (*free)(cr8r_base_ft*, void*);
69 
89 
93 
96 
103 
113 
120 
125 
132 
cr8r_pheap_node * cr8r_pheap_new(void *key, cr8r_pheap_ft *, cr8r_pheap_node *first_child, cr8r_pheap_node *sibling, cr8r_pheap_node *parent)
Allocate a new pairing heap node using ft->alloc and initialize it.
void cr8r_pheap_delete(cr8r_pheap_node *, cr8r_pheap_ft *)
Delete all nodes in a pairing heap.
cr8r_pheap_node * cr8r_pheap_pop(cr8r_pheap_node **r, cr8r_pheap_ft *)
Remove the root (minimal) element from a pairing heap.
void * cr8r_pheap_top(cr8r_pheap_node *, cr8r_pheap_ft *)
Return a pointer to the minimal data element of a pairing heap, or NULL if the heap is empty.
cr8r_pheap_node * cr8r_pheap_root(cr8r_pheap_node *)
Return a pointer to the root node given a pointer to any node in a heap.
cr8r_pheap_node * cr8r_pheap_decreased_key(cr8r_pheap_node *n, cr8r_pheap_ft *)
Restore the (min) heap invariant after decreasing the key of a node.
cr8r_pheap_node * cr8r_pheap_meld(cr8r_pheap_node *a, cr8r_pheap_node *b, cr8r_pheap_ft *)
Combine two pairing heaps, invalidating them The nodes of the existing heaps are reused and re-linked...
cr8r_pheap_node * cr8r_pheap_push(cr8r_pheap_node *, void *key, cr8r_pheap_ft *)
Insert an item into a pairing heap Allocates and initializes a new node for the new item.
Base function table for all Crater containers.
Definition: container.h:22
function table for pairing heaps note that since this is an intrusive data structure,...
Definition: pheap.h:48
cr8r_base_ft base
Base function table values (data and size)
Definition: pheap.h:50
cr8r_pheap_node * parent
pointer to the parent
Definition: pheap.h:40
cr8r_pheap_node * first_child
pointer to the first child (or NULL). All children form a circularly linked list
Definition: pheap.h:36
cr8r_pheap_node * sibling
pointer to the next sibling. These are the pointers that form a cll.
Definition: pheap.h:38