gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10246 - in GNUnet/src: include util/containers


From: gnunet
Subject: [GNUnet-SVN] r10246 - in GNUnet/src: include util/containers
Date: Sun, 7 Feb 2010 20:33:11 +0100

Author: nevans
Date: 2010-02-07 20:33:11 +0100 (Sun, 07 Feb 2010)
New Revision: 10246

Modified:
   GNUnet/src/include/gnunet_util_containers.h
   GNUnet/src/util/containers/heap.c
   GNUnet/src/util/containers/heaptest.c
Log:
revert broken heap changes

Modified: GNUnet/src/include/gnunet_util_containers.h
===================================================================
--- GNUnet/src/include/gnunet_util_containers.h 2010-02-07 15:00:34 UTC (rev 
10245)
+++ GNUnet/src/include/gnunet_util_containers.h 2010-02-07 19:33:11 UTC (rev 
10246)
@@ -600,7 +600,7 @@
 };
 
 
-/** 
+/**
  * Handle to a heap.
  */
 struct GNUNET_CONTAINER_Heap;
@@ -676,7 +676,7 @@
  * @param iterator_cls closure for iterator
  */
 void
-GNUNET_CONTAINER_heap_iterate (struct GNUNET_CONTAINER_Heap *heap,
+GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
                                GNUNET_CONTAINER_HeapIterator iterator,
                                void *iterator_cls);
 
@@ -723,7 +723,7 @@
 
 /**
  * Removes a node from the heap.
- * 
+ *
  * @param heap heap to modify
  * @param node node to remove
  * @return element data stored at the node, NULL if heap is empty

Modified: GNUnet/src/util/containers/heap.c
===================================================================
--- GNUnet/src/util/containers/heap.c   2010-02-07 15:00:34 UTC (rev 10245)
+++ GNUnet/src/util/containers/heap.c   2010-02-07 19:33:11 UTC (rev 10246)
@@ -69,11 +69,6 @@
    */
   unsigned int tree_size;
 
-  /*
-   * Is this node scheduled to be deleted?
-   */
-  unsigned int delete;
-
 };
 
 /**
@@ -102,20 +97,6 @@
    */
   enum GNUNET_CONTAINER_HeapOrder order;
 
-  /*
-   * Is the heap dirty (needs expunged)?
-   */
-  unsigned int dirty;
-
-  /*
-   * How many iterations are we into this heap?
-   *
-   * 0 - if no iteration(s) taking place
-   *   > 0 if iteration(s) in progress
-   *   < 0 if we are currently cleaning up the heap (removing dead nodes)!
-   */
-  int iterator_count;
-
 };
 
 
@@ -159,8 +140,6 @@
   struct GNUNET_CONTAINER_Heap *heap;
 
   heap = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_Heap));
-  heap->dirty = GNUNET_NO;
-  heap->iterator_count = 0;
   heap->order = order;
   return heap;
 }
@@ -230,51 +209,11 @@
   if (GNUNET_YES != node_iterator (heap,
                                    node->right_child, iterator, iterator_cls))
     return GNUNET_NO;
-
-  if (node->delete == GNUNET_NO)
-    return iterator (iterator_cls, node, node->element, node->cost);
-  else
-    return GNUNET_NO;
+  return iterator (iterator_cls, node, node->element, node->cost);
 }
 
 
 /**
- * Iterate over the children of the given node.
- *
- * @param heap argument to give to iterator
- * @param node node to iterate over
- * @param iterator function to call on each node
- * @param iterator_cls closure for iterator
- * @return GNUNET_YES to continue to iterate
- */
-void
-cleanup_node_iterator (struct GNUNET_CONTAINER_Heap *heap,
-               struct GNUNET_CONTAINER_HeapNode *node)
-{
-  if (node == NULL)
-    return;
-
-  if (node->left_child != NULL)
-    cleanup_node_iterator(heap, node->left_child);
-  if (node->right_child != NULL)
-    cleanup_node_iterator(heap, node->right_child);
-
-  if (node->delete == GNUNET_YES)
-    {
-      if (heap->root == node)
-        GNUNET_CONTAINER_heap_remove_node (heap, node);
-      else
-        GNUNET_CONTAINER_heap_remove_root (heap);
-    }
-  return;
-}
-
-void cleanup_heap(struct GNUNET_CONTAINER_Heap *heap)
-{
-  cleanup_node_iterator(heap, heap->root);
-  heap->dirty = GNUNET_NO;
-}
-/**
  * Iterate over all entries in the heap.
  *
  * @param heap the heap
@@ -282,16 +221,11 @@
  * @param iterator_cls closure for iterator
  */
 void
-GNUNET_CONTAINER_heap_iterate (struct GNUNET_CONTAINER_Heap *heap,
+GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
                                GNUNET_CONTAINER_HeapIterator iterator,
                                void *iterator_cls)
 {
-  heap->iterator_count++;
   (void) node_iterator (heap, heap->root, iterator, iterator_cls);
-  heap->iterator_count--;
-
-  if (heap->iterator_count == 0)
-    cleanup_heap(heap);
 }
 
 
@@ -427,18 +361,8 @@
 
   if (NULL == (root = heap->root))
     return NULL;
-
-  ret = root->element;
-  if (heap->iterator_count != 0)
-    {
-      heap->root->delete = GNUNET_YES;
-      if (heap->dirty == GNUNET_NO)
-        heap->dirty = GNUNET_YES;
-
-      return ret;
-    }
   heap->size--;
-
+  ret = root->element;
   if (root->left_child == NULL)
     {
       heap->root = root->right_child;
@@ -542,7 +466,7 @@
 
 /**
  * Removes a node from the heap.
- *
+ * 
  * @param heap heap to modify
  * @param node node to remove
  * @return element data stored at the node
@@ -554,16 +478,6 @@
   void *ret;
 
   CHECK (heap->root);
-
-  ret = node->element;
-  if (heap->iterator_count != 0)
-    {
-      node->delete = GNUNET_YES;
-      if (heap->dirty == GNUNET_NO)
-        heap->dirty = GNUNET_YES;
-      return ret;
-    }
-
   if (heap->walk_pos == node)
     (void) GNUNET_CONTAINER_heap_walk_get_next (heap);
   remove_node (heap, node);

Modified: GNUnet/src/util/containers/heaptest.c
===================================================================
--- GNUnet/src/util/containers/heaptest.c       2010-02-07 15:00:34 UTC (rev 
10245)
+++ GNUnet/src/util/containers/heaptest.c       2010-02-07 19:33:11 UTC (rev 
10246)
@@ -49,27 +49,13 @@
   unsigned int cost;
 };
 
-static struct GNUNET_CONTAINER_Heap *minHeap;
-static struct GNUNET_CONTAINER_Heap *maxHeap;
 
-static int
-iterator_callback (void *cls,
-                   struct GNUNET_CONTAINER_HeapNode * node,
-                   void *element,
-                   GNUNET_CONTAINER_HeapCostType cost)
-{
-  struct GNUNET_neighbor *neighbor = element;
-#if DEBUG
-  fprintf(stderr, "Iterating, at neighbor %u with cost %u\n", 
neighbor->neighbor, neighbor->cost);
-#endif
-  GNUNET_CONTAINER_heap_remove_node (maxHeap, node);
-  return GNUNET_YES;
-
-}
-
 int
 main (int argc, char **argv)
 {
+
+  struct GNUNET_CONTAINER_Heap *minHeap;
+  struct GNUNET_CONTAINER_Heap *maxHeap;
   int i;
   int ret;
   int cur_pos = 0;
@@ -151,9 +137,6 @@
         return GNUNET_SYSERR;
 
     }
-
-  GNUNET_CONTAINER_heap_iterate(maxHeap, &iterator_callback, NULL);
-
   while (GNUNET_CONTAINER_heap_get_size (maxHeap) > 0)
     {
       GNUNET_CONTAINER_heap_remove_root (maxHeap);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]