gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r34037 - gnunet/src/dht


From: gnunet
Subject: [GNUnet-SVN] r34037 - gnunet/src/dht
Date: Thu, 24 Jul 2014 14:19:27 +0200

Author: supriti
Date: 2014-07-24 14:19:27 +0200 (Thu, 24 Jul 2014)
New Revision: 34037

Modified:
   gnunet/src/dht/gnunet-service-xdht_neighbours.c
Log:
Calculating index from finger value and my identity using shift operation


Modified: gnunet/src/dht/gnunet-service-xdht_neighbours.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_neighbours.c     2014-07-24 12:18:12 UTC 
(rev 34036)
+++ gnunet/src/dht/gnunet-service-xdht_neighbours.c     2014-07-24 12:19:27 UTC 
(rev 34037)
@@ -3172,6 +3172,28 @@
 
 
 /**
+ * Get the first set bit in val. 
+ * @param val Value
+ * @return Position of first bit set.
+ */
+static unsigned int
+find_set_bit(uint64_t val)
+{
+  uint64_t i;
+  unsigned int pos;
+  
+  i = 1;
+  pos = 0;
+  
+  while(!(i && val))
+  {
+    i = i << val;
+    pos++;
+  }
+  return pos;
+}
+
+/**
  * Calculate finger_table_index from initial 64 bit finger identity value that 
  * we send in trail setup message. 
  * @param ultimate_destination_finger_value Value that we calculated from our
@@ -3186,7 +3208,7 @@
                         unsigned int is_predecessor)
 {
   uint64_t my_id64;
-  int diff;
+  uint64_t diff;
   unsigned int finger_table_index;
 
   memcpy (&my_id64, &my_identity, sizeof (uint64_t));
@@ -3205,7 +3227,7 @@
   else 
   {
     diff = ultimate_destination_finger_value - my_id64;
-    finger_table_index = (log10 (diff))/(log10 (2));
+    finger_table_index = find_set_bit(diff);
   }
   
   return finger_table_index;




reply via email to

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