Implementation of a heap. More...
Go to the source code of this file.
Data Structures | |
struct | GNUNET_CONTAINER_HeapNode |
Node in the heap. More... | |
struct | GNUNET_CONTAINER_Heap |
Handle to a node in a heap. More... | |
Macros | |
#define | LOG(kind, ...) |
#define | EXTRA_CHECKS 0 |
#define | CHECK(n) do {} while (0) |
Functions | |
struct GNUNET_CONTAINER_Heap * | GNUNET_CONTAINER_heap_create (enum GNUNET_CONTAINER_HeapOrder order) |
Create a new heap. More... | |
void | GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap) |
Destroys the heap. More... | |
void * | GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap) |
Get element stored at the root of heap. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap, void **element, GNUNET_CONTAINER_HeapCostType *cost) |
Get element and cost stored at the root of heap. More... | |
unsigned int | GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap) |
Get the current size of the heap. More... | |
GNUNET_CONTAINER_HeapCostType | GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode *node) |
Get the current cost of the node. More... | |
static int | node_iterator (const struct GNUNET_CONTAINER_Heap *heap, struct GNUNET_CONTAINER_HeapNode *node, GNUNET_CONTAINER_HeapIterator iterator, void *iterator_cls) |
Iterate over the children of the given node. More... | |
void | GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap, GNUNET_CONTAINER_HeapIterator iterator, void *iterator_cls) |
Iterate over all entries in the heap. More... | |
void * | GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap) |
Perform a random walk of the tree. More... | |
static void | insert_node (struct GNUNET_CONTAINER_Heap *heap, struct GNUNET_CONTAINER_HeapNode *pos, struct GNUNET_CONTAINER_HeapNode *node) |
Insert the given node 'node' into the subtree starting at 'pos' (while keeping the tree somewhat balanced). More... | |
struct GNUNET_CONTAINER_HeapNode * | GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, void *element, GNUNET_CONTAINER_HeapCostType cost) |
Inserts a new element into the heap. More... | |
void * | GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap) |
Remove root of the heap. More... | |
static void | remove_node (struct GNUNET_CONTAINER_HeapNode *node) |
Remove the given node 'node' from the tree and update the 'tree_size' fields accordingly. More... | |
void * | GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node) |
Removes a node from the heap. More... | |
void | GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_HeapNode *node, GNUNET_CONTAINER_HeapCostType new_cost) |
Updates the cost of any node in the tree. More... | |
Implementation of a heap.
Definition in file container_heap.c.
#define LOG | ( | kind, | |
... | |||
) |
Definition at line 32 of file container_heap.c.
#define EXTRA_CHECKS 0 |
Definition at line 35 of file container_heap.c.
#define CHECK | ( | n | ) | do {} while (0) |
Definition at line 129 of file container_heap.c.
|
static |
Iterate over the children of the given node.
heap | argument to give to iterator |
node | node to iterate over |
iterator | function to call on each node |
iterator_cls | closure for iterator |
Definition at line 210 of file container_heap.c.
References GNUNET_CONTAINER_HeapNode::cost, GNUNET_CONTAINER_HeapNode::element, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_HeapNode::left_child, node_iterator(), and GNUNET_CONTAINER_HeapNode::right_child.
Referenced by GNUNET_CONTAINER_heap_iterate(), and node_iterator().
|
static |
Insert the given node 'node' into the subtree starting at 'pos' (while keeping the tree somewhat balanced).
heap | heap to modify |
pos | existing tree |
node | node to insert (which may be a subtree itself) |
Definition at line 264 of file container_heap.c.
References CHECK, GNUNET_CONTAINER_HeapNode::cost, GNUNET_assert, GNUNET_CONTAINER_HEAP_ORDER_MAX, GNUNET_CONTAINER_HeapNode::heap, insert_node(), GNUNET_CONTAINER_HeapNode::left_child, GNUNET_CONTAINER_Heap::order, GNUNET_CONTAINER_HeapNode::parent, GNUNET_CONTAINER_HeapNode::right_child, GNUNET_CONTAINER_Heap::root, and GNUNET_CONTAINER_HeapNode::tree_size.
Referenced by GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_heap_remove_root(), GNUNET_CONTAINER_heap_update_cost(), insert_node(), and remove_node().
|
static |
Remove the given node 'node' from the tree and update the 'tree_size' fields accordingly.
Preserves the children of 'node' and does NOT change the overall 'size' field of the tree.
Definition at line 390 of file container_heap.c.
References CHECK, GNUNET_assert, GNUNET_CONTAINER_HeapNode::heap, insert_node(), GNUNET_CONTAINER_HeapNode::left_child, GNUNET_CONTAINER_HeapNode::parent, GNUNET_CONTAINER_HeapNode::right_child, GNUNET_CONTAINER_Heap::root, and GNUNET_CONTAINER_HeapNode::tree_size.
Referenced by GNUNET_CONTAINER_heap_remove_node(), and GNUNET_CONTAINER_heap_update_cost().