diff options
author | Julius Bünger <buenger@mytum.de> | 2015-01-07 14:00:13 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-01-07 14:00:13 +0000 |
commit | 6a08ce6a247df3247a9e89500a6381c9ca205bac (patch) | |
tree | 50793c79141c38d0787e517fe86e5ca71f008252 /src/rps/gnunet-service-rps_sampler.c | |
parent | c1fc2480f5e95ff937a1bf0f67410701465ed698 (diff) | |
download | gnunet-6a08ce6a247df3247a9e89500a6381c9ca205bac.tar.gz gnunet-6a08ce6a247df3247a9e89500a6381c9ca205bac.zip |
moved part of _resize() from _sampler.c to -rps.c
Diffstat (limited to 'src/rps/gnunet-service-rps_sampler.c')
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index f80a70108..66a9ec4e9 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -156,7 +156,7 @@ static size_t extra_size; | |||
156 | /** | 156 | /** |
157 | * Inedex to the sampler element that is the next to be returned | 157 | * Inedex to the sampler element that is the next to be returned |
158 | */ | 158 | */ |
159 | static struct RPS_SamplerElement **extended_samplers_index; | 159 | static uint64_t extended_samplers_index; |
160 | 160 | ||
161 | /** | 161 | /** |
162 | * Request counter. | 162 | * Request counter. |
@@ -349,17 +349,13 @@ RPS_sampler_resize (unsigned int new_size) | |||
349 | 349 | ||
350 | old_size = sampler->sampler_size; | 350 | old_size = sampler->sampler_size; |
351 | 351 | ||
352 | if (old_size > new_size*4 && | 352 | if (old_size > new_size) |
353 | extra_size > new_size*4) | ||
354 | { /* Shrinking */ | 353 | { /* Shrinking */ |
355 | |||
356 | new_size /= 2; | ||
357 | |||
358 | /* Temporary store those to properly call the removeCB on those later */ | 354 | /* Temporary store those to properly call the removeCB on those later */ |
359 | rem_list = GNUNET_malloc ((old_size - new_size) * sizeof (struct RPS_SamplerElement *)); | 355 | rem_list = GNUNET_malloc ((old_size - new_size) * sizeof (struct RPS_SamplerElement *)); |
360 | memcpy (rem_list, | 356 | memcpy (rem_list, |
361 | &sampler->sampler_elements[new_size], | 357 | &sampler->sampler_elements[new_size], |
362 | (old_size - new_size) * sizeof(struct RPS_SamplerElement *)); | 358 | (old_size - new_size) * sizeof (struct RPS_SamplerElement *)); |
363 | 359 | ||
364 | LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Shrinking sampler %d -> %d\n", old_size, new_size); | 360 | LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Shrinking sampler %d -> %d\n", old_size, new_size); |
365 | GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, new_size); | 361 | GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, new_size); |
@@ -367,7 +363,6 @@ RPS_sampler_resize (unsigned int new_size) | |||
367 | "SAMPLER: sampler->sampler_elements now points to %p\n", | 363 | "SAMPLER: sampler->sampler_elements now points to %p\n", |
368 | sampler->sampler_elements); | 364 | sampler->sampler_elements); |
369 | 365 | ||
370 | // TODO move extended_samplers_index | ||
371 | for (i = new_size ; i < old_size ; i++) | 366 | for (i = new_size ; i < old_size ; i++) |
372 | {/* Remove unneeded rest */ | 367 | {/* Remove unneeded rest */ |
373 | LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Removing %" PRIX64 ". sampler\n", i); | 368 | LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Removing %" PRIX64 ". sampler\n", i); |
@@ -376,19 +371,14 @@ RPS_sampler_resize (unsigned int new_size) | |||
376 | GNUNET_free (rem_list[i]); | 371 | GNUNET_free (rem_list[i]); |
377 | } | 372 | } |
378 | } | 373 | } |
379 | else if (old_size < new_size)// || | 374 | else if (old_size < new_size) |
380 | //extra_size < new_size) // needed? | ||
381 | { /* Growing */ | 375 | { /* Growing */ |
382 | new_size *= 2; // TODO check overflow | ||
383 | |||
384 | LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Growing sampler %d -> %d\n", old_size, new_size); | 376 | LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Growing sampler %d -> %d\n", old_size, new_size); |
385 | GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, new_size); | 377 | GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, new_size); |
386 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 378 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
387 | "SAMPLER: sampler->sampler_elements now points to %p\n", | 379 | "SAMPLER: sampler->sampler_elements now points to %p\n", |
388 | sampler->sampler_elements); | 380 | sampler->sampler_elements); |
389 | 381 | ||
390 | // TODO move extended_samplers_index | ||
391 | |||
392 | for ( i = old_size ; i < new_size ; i++ ) | 382 | for ( i = old_size ; i < new_size ; i++ ) |
393 | { /* Add new sampler elements */ | 383 | { /* Add new sampler elements */ |
394 | sampler->sampler_elements[i] = RPS_sampler_elem_create (); | 384 | sampler->sampler_elements[i] = RPS_sampler_elem_create (); |
@@ -447,7 +437,7 @@ RPS_sampler_init (size_t init_size, const struct GNUNET_PeerIdentity *id, | |||
447 | RPS_sampler_resize (init_size); | 437 | RPS_sampler_resize (init_size); |
448 | RPS_sampler_update_list (id); // no super nice desing but ok for the moment | 438 | RPS_sampler_update_list (id); // no super nice desing but ok for the moment |
449 | 439 | ||
450 | extended_samplers_index = sampler->sampler_elements; | 440 | extended_samplers_index = 0; |
451 | 441 | ||
452 | //GNUNET_assert (init_size == sampler->sampler_size); | 442 | //GNUNET_assert (init_size == sampler->sampler_size); |
453 | } | 443 | } |
@@ -591,13 +581,12 @@ RPS_sampler_get_rand_peer () | |||
591 | 581 | ||
592 | // use _get_rand_peer_ ? | 582 | // use _get_rand_peer_ ? |
593 | peer = GNUNET_new (struct GNUNET_PeerIdentity); | 583 | peer = GNUNET_new (struct GNUNET_PeerIdentity); |
594 | *peer = (*extended_samplers_index)->peer_id; | 584 | *peer = sampler->sampler_elements[extended_samplers_index]->peer_id; |
595 | RPS_sampler_elem_reinit (*extended_samplers_index); | 585 | RPS_sampler_elem_reinit (sampler->sampler_elements[extended_samplers_index]); |
596 | if ( extended_samplers_index == &sampler->sampler_elements[sampler->sampler_size -1] ) | 586 | if ( extended_samplers_index == sampler->sampler_size ) |
597 | extended_samplers_index = &sampler->sampler_elements[0]; | 587 | extended_samplers_index = 0; |
598 | else | 588 | else |
599 | extended_samplers_index++; | 589 | extended_samplers_index++; |
600 | // TODO | ||
601 | return peer; | 590 | return peer; |
602 | } | 591 | } |
603 | 592 | ||