/**
* Cost by which elements in a heap can be ordered.
*/
-typedef unsigned int GNUNET_CONTAINER_HeapCost;
+typedef uint64_t GNUNET_CONTAINER_HeapCost;
+
/*
* Heap type, either max or min. Hopefully makes the
GNUNET_CONTAINER_HEAP_ORDER_MIN
};
+
/**
* Handle to a Heap.
*/
GNUNET_CONTAINER_HeapOrder
type);
+
/**
* Free a heap
*
*/
void GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *h);
+
/**
* Function called on elements of a heap.
*
typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls,
void *element,
GNUNET_CONTAINER_HeapCost cost);
+
+
/**
* Iterate over all entries in the map.
*
void *iterator_cls);
+
/**
* Inserts a new item into the heap, item is always neighbor now.
* @param heap the heap
GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap,
void *element, GNUNET_CONTAINER_HeapCost cost);
+
/**
* Removes root of the tree, is remove max if a max heap and remove min
* if a min heap, returns the data stored at the node.
*/
void *GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
+
/**
* Returns element stored at root of tree, doesn't effect anything
*
*/
void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap);
+
/**
* Removes any node from the tree based on the neighbor given, does
* not traverse the tree (backpointers) but may take more time due to
void *GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_Heap *heap,
void *element);
+
/**
* Updates the cost of any node in the tree
*
void *element,
GNUNET_CONTAINER_HeapCost new_cost);
+
/**
* Random walk of the tree, returns the data stored at the next random node
* in the walk. Calls callee with the data, or NULL if the tree is empty
void *GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap
*heap);
+
/**
* Returns the current size of the heap
*
GNUNET_CONTAINER_heap_get_size (struct GNUNET_CONTAINER_Heap *heap);
+
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
};
+
+/**
+ * Returns element stored at root of tree, doesn't effect anything
+ *
+ * @param heap the heap
+ * @return NULL if the heap is empty
+ */
+void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap)
+{
+ return heap->root;
+}
+
+
void
internal_print (struct GNUNET_CONTAINER_heap_node *root)
{
- fprintf (stdout, "%d\n", root->cost);
+ fprintf (stdout, "%llu\n", (unsigned long long) root->cost);
if (root->left_child != NULL)
{
- fprintf (stdout, "LEFT of %d\n", root->cost);
+ fprintf (stdout, "LEFT of %llu\n", (unsigned long long) root->cost);
internal_print (root->left_child);
}
if (root->right_child != NULL)
{
- fprintf (stdout, "RIGHT of %d\n", root->cost);
+ fprintf (stdout, "RIGHT of %llu\n", (unsigned long long) root->cost);
internal_print (root->right_child);
}
}