From f211dbecd475ad630e54b29e2bd054c139aa1273 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 28 Jan 2015 16:56:47 +0000 Subject: - never resize to 0 --- src/rps/gnunet-service-rps.c | 4 ++-- src/rps/gnunet-service-rps_sampler.c | 29 +++++++++++++++++++++++++++-- src/rps/gnunet-service-rps_sampler.h | 9 +++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 4a0027d72..e3e2c02c0 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c @@ -790,11 +790,11 @@ nse_callback (void *cls, struct GNUNET_TIME_Absolute timestamp, LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n", - logestimate, std_dev, RPS_sampler_get_size()); + logestimate, std_dev, RPS_sampler_get_size ()); //scale = .01; estimate = GNUNET_NSE_log_estimate_to_n (logestimate); // GNUNET_NSE_log_estimate_to_n (logestimate); - estimate = pow (estimate, 1./3); + estimate = pow (estimate, 1.0 / 3); // TODO add if std_dev is a number // estimate += (std_dev * scale); if (0 < ceil (estimate)) diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index 01d8aa748..419110440 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c @@ -417,8 +417,8 @@ RPS_sampler_get_size () * * @param new_size the new size of the sampler */ - void -RPS_sampler_resize (unsigned int new_size) +static void +sampler_resize (unsigned int new_size) { unsigned int old_size; uint32_t i; @@ -480,6 +480,31 @@ RPS_sampler_resize (unsigned int new_size) } +/** + * Grow or shrink the size of the sampler. + * + * @param new_size the new size of the sampler + */ +void +RPS_sampler_resize (unsigned int new_size) +{ + GNUNET_assert (0 < new_size); + sampler_resize (new_size); +} + + +/** + * Empty the sampler. + * + * @param new_size the new size of the sampler + */ +void +RPS_sampler_empty () +{ + sampler_resize (0); +} + + /** * Initialise a tuple of sampler elements. * diff --git a/src/rps/gnunet-service-rps_sampler.h b/src/rps/gnunet-service-rps_sampler.h index 4949ef9c6..d0ac11d0d 100644 --- a/src/rps/gnunet-service-rps_sampler.h +++ b/src/rps/gnunet-service-rps_sampler.h @@ -83,6 +83,15 @@ RPS_sampler_get_size (); RPS_sampler_resize (unsigned int new_size); +/** + * Empty the sampler. + * + * @param new_size the new size of the sampler + */ +void +RPS_sampler_empty (); + + /** * Initialise a tuple of samplers. * -- cgit v1.2.3