gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r8853 - GNUnet/src/util/containers


From: gnunet
Subject: [GNUnet-SVN] r8853 - GNUnet/src/util/containers
Date: Tue, 25 Aug 2009 12:55:50 -0600

Author: nevans
Date: 2009-08-25 12:55:49 -0600 (Tue, 25 Aug 2009)
New Revision: 8853

Modified:
   GNUnet/src/util/containers/heap.c
   GNUnet/src/util/containers/multihashmap.c
Log:
precommit and random hash map value change

Modified: GNUnet/src/util/containers/heap.c
===================================================================
--- GNUnet/src/util/containers/heap.c   2009-08-25 18:54:47 UTC (rev 8852)
+++ GNUnet/src/util/containers/heap.c   2009-08-25 18:55:49 UTC (rev 8853)
@@ -74,7 +74,7 @@
 };
 
 int
-next_power_of_2(int v)
+next_power_of_2 (int v)
 {
   v |= v >> 1;
   v |= v >> 2;
@@ -88,15 +88,15 @@
 void
 internal_print (struct GNUNET_CONTAINER_heap_node *root)
 {
-  fprintf (stdout, "%d\n", (int)root->cost);
+  fprintf (stdout, "%d\n", (int) root->cost);
   if (root->left_child != NULL)
     {
-      fprintf (stdout, "LEFT of %d\n", (int)root->cost);
+      fprintf (stdout, "LEFT of %d\n", (int) root->cost);
       internal_print (root->left_child);
     }
   if (root->right_child != NULL)
     {
-      fprintf (stdout, "RIGHT of %d\n", (int)root->cost);
+      fprintf (stdout, "RIGHT of %d\n", (int) root->cost);
       internal_print (root->right_child);
     }
 }
@@ -178,7 +178,7 @@
   else
     {
       parent = root->root;
-      for (i = next_power_of_2(pos) >> 2; i > 1; i >>= 1)
+      for (i = next_power_of_2 (pos) >> 2; i > 1; i >>= 1)
         {
           if (((pos / i) % 2) == 0)
             parent = parent->left_child;
@@ -212,7 +212,7 @@
   else
     {
       ret = root->root;
-      for (i = next_power_of_2(pos) >> 2; i > 0; i >>= 1)
+      for (i = next_power_of_2 (pos) >> 2; i > 0; i >>= 1)
         {
           if (((pos / i) % 2) == 0)
             ret = ret->left_child;

Modified: GNUnet/src/util/containers/multihashmap.c
===================================================================
--- GNUnet/src/util/containers/multihashmap.c   2009-08-25 18:54:47 UTC (rev 
8852)
+++ GNUnet/src/util/containers/multihashmap.c   2009-08-25 18:55:49 UTC (rev 
8853)
@@ -301,6 +301,8 @@
 GNUNET_multi_hash_map_get_random (const struct GNUNET_MultiHashMap *map)
 {
   unsigned int rand;
+  unsigned int rand_entry;
+  unsigned int count;
   struct MapEntry *e;
   e = NULL;
 
@@ -313,6 +315,22 @@
       e = map->map[rand];
     }
 
+  count = 0;
+  while (e != NULL)
+    {
+      e = e->next;
+      count++;
+    }
+
+  rand_entry = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, count);
+  e = map->map[rand];
+  count = 0;
+  while (count < rand_entry)
+    {
+      e = e->next;
+      count++;
+    }
+
   return e->value;
 }
 





reply via email to

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