heap fixes
authorChristian Grothoff <christian@grothoff.org>
Tue, 22 Sep 2009 17:33:51 +0000 (17:33 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 22 Sep 2009 17:33:51 +0000 (17:33 +0000)
src/include/gnunet_container_lib.h
src/util/container_heap.c

index 79d7866ed016144f6c2268cb3879340bf5b38a51..61dee99181474e1a2626351c037a7ab6902bb8c5 100644 (file)
@@ -689,7 +689,8 @@ void *GNUNET_CONTAINER_multihashmap_get_random (const struct
 /**
  * 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
@@ -708,6 +709,7 @@ enum GNUNET_CONTAINER_HeapOrder
   GNUNET_CONTAINER_HEAP_ORDER_MIN
 };
 
+
 /**
  * Handle to a Heap.
  */
@@ -723,6 +725,7 @@ struct GNUNET_CONTAINER_Heap *GNUNET_CONTAINER_heap_create (enum
                                                             GNUNET_CONTAINER_HeapOrder
                                                             type);
 
+
 /**
  * Free a heap
  *
@@ -730,6 +733,7 @@ struct GNUNET_CONTAINER_Heap *GNUNET_CONTAINER_heap_create (enum
  */
 void GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *h);
 
+
 /**
  * Function called on elements of a heap.
  *
@@ -742,6 +746,8 @@ void GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *h);
 typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls,
                                               void *element,
                                               GNUNET_CONTAINER_HeapCost cost);
+
+
 /**
  * Iterate over all entries in the map.
  *
@@ -756,6 +762,7 @@ int GNUNET_CONTAINER_heap_iterate (struct GNUNET_CONTAINER_Heap *heap,
                                    void *iterator_cls);
 
 
+
 /**
  * Inserts a new item into the heap, item is always neighbor now.
  * @param heap the heap
@@ -764,6 +771,7 @@ int
 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.
@@ -773,6 +781,7 @@ GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap,
  */
 void *GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
 
+
 /**
  * Returns element stored at root of tree, doesn't effect anything
  *
@@ -781,6 +790,7 @@ void *GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
  */
 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
@@ -790,6 +800,7 @@ void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap);
 void *GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_Heap *heap,
                                          void *element);
 
+
 /**
  * Updates the cost of any node in the tree
  *
@@ -803,6 +814,7 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
                                    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
@@ -814,6 +826,7 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
 void *GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap
                                            *heap);
 
+
 /**
  * Returns the current size of the heap
  *
@@ -824,6 +837,7 @@ unsigned int
 GNUNET_CONTAINER_heap_get_size (struct GNUNET_CONTAINER_Heap *heap);
 
 
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif
index 7e41c40f251ab3bc4f07cb24043800af385140cd..fd5838f60cdccd449d92ef867b0a5644241079f7 100644 (file)
@@ -72,18 +72,31 @@ struct GNUNET_CONTAINER_Heap
 
 };
 
+
+/**
+ * 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);
     }
 }