diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-07-24 12:19:27 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-07-24 12:19:27 +0000 |
commit | f2594744c121f45f3b36867b051220e7186d6f9b (patch) | |
tree | a8475f885933205a99417805f900ef0105d3c0d3 /src | |
parent | 65dd03a6e5497e16bee7ec3a68f12addc1eb3c92 (diff) | |
download | gnunet-f2594744c121f45f3b36867b051220e7186d6f9b.tar.gz gnunet-f2594744c121f45f3b36867b051220e7186d6f9b.zip |
Calculating index from finger value and my identity using shift operation
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 976e2be75..97e983b56 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -3172,6 +3172,28 @@ update_current_search_finger_index (struct GNUNET_PeerIdentity finger_identity, | |||
3172 | 3172 | ||
3173 | 3173 | ||
3174 | /** | 3174 | /** |
3175 | * Get the first set bit in val. | ||
3176 | * @param val Value | ||
3177 | * @return Position of first bit set. | ||
3178 | */ | ||
3179 | static unsigned int | ||
3180 | find_set_bit(uint64_t val) | ||
3181 | { | ||
3182 | uint64_t i; | ||
3183 | unsigned int pos; | ||
3184 | |||
3185 | i = 1; | ||
3186 | pos = 0; | ||
3187 | |||
3188 | while(!(i && val)) | ||
3189 | { | ||
3190 | i = i << val; | ||
3191 | pos++; | ||
3192 | } | ||
3193 | return pos; | ||
3194 | } | ||
3195 | |||
3196 | /** | ||
3175 | * Calculate finger_table_index from initial 64 bit finger identity value that | 3197 | * Calculate finger_table_index from initial 64 bit finger identity value that |
3176 | * we send in trail setup message. | 3198 | * we send in trail setup message. |
3177 | * @param ultimate_destination_finger_value Value that we calculated from our | 3199 | * @param ultimate_destination_finger_value Value that we calculated from our |
@@ -3186,7 +3208,7 @@ get_finger_table_index (uint64_t ultimate_destination_finger_value, | |||
3186 | unsigned int is_predecessor) | 3208 | unsigned int is_predecessor) |
3187 | { | 3209 | { |
3188 | uint64_t my_id64; | 3210 | uint64_t my_id64; |
3189 | int diff; | 3211 | uint64_t diff; |
3190 | unsigned int finger_table_index; | 3212 | unsigned int finger_table_index; |
3191 | 3213 | ||
3192 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); | 3214 | memcpy (&my_id64, &my_identity, sizeof (uint64_t)); |
@@ -3205,7 +3227,7 @@ get_finger_table_index (uint64_t ultimate_destination_finger_value, | |||
3205 | else | 3227 | else |
3206 | { | 3228 | { |
3207 | diff = ultimate_destination_finger_value - my_id64; | 3229 | diff = ultimate_destination_finger_value - my_id64; |
3208 | finger_table_index = (log10 (diff))/(log10 (2)); | 3230 | finger_table_index = find_set_bit(diff); |
3209 | } | 3231 | } |
3210 | 3232 | ||
3211 | return finger_table_index; | 3233 | return finger_table_index; |