diff options
Diffstat (limited to 'src/setu/gnunet-service-setu_strata_estimator.c')
-rw-r--r-- | src/setu/gnunet-service-setu_strata_estimator.c | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/src/setu/gnunet-service-setu_strata_estimator.c b/src/setu/gnunet-service-setu_strata_estimator.c index 0fa6a6f17..32898f482 100644 --- a/src/setu/gnunet-service-setu_strata_estimator.c +++ b/src/setu/gnunet-service-setu_strata_estimator.c | |||
@@ -30,13 +30,6 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Should we try compressing the strata estimator? This will | ||
34 | * break compatibility with the 0.10.1-network. | ||
35 | */ | ||
36 | #define FAIL_10_1_COMPATIBILTIY 1 | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Write the given strata estimator to the buffer. | 33 | * Write the given strata estimator to the buffer. |
41 | * | 34 | * |
42 | * @param se strata estimator to serialize | 35 | * @param se strata estimator to serialize |
@@ -48,11 +41,10 @@ strata_estimator_write (const struct StrataEstimator *se, | |||
48 | void *buf) | 41 | void *buf) |
49 | { | 42 | { |
50 | char *sbuf = buf; | 43 | char *sbuf = buf; |
51 | unsigned int i; | ||
52 | size_t osize; | 44 | size_t osize; |
53 | 45 | ||
54 | GNUNET_assert (NULL != se); | 46 | GNUNET_assert (NULL != se); |
55 | for (i = 0; i < se->strata_count; i++) | 47 | for (unsigned int i = 0; i < se->strata_count; i++) |
56 | { | 48 | { |
57 | ibf_write_slice (se->strata[i], | 49 | ibf_write_slice (se->strata[i], |
58 | 0, | 50 | 0, |
@@ -60,7 +52,6 @@ strata_estimator_write (const struct StrataEstimator *se, | |||
60 | &sbuf[se->ibf_size * IBF_BUCKET_SIZE * i]); | 52 | &sbuf[se->ibf_size * IBF_BUCKET_SIZE * i]); |
61 | } | 53 | } |
62 | osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count; | 54 | osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count; |
63 | #if FAIL_10_1_COMPATIBILTIY | ||
64 | { | 55 | { |
65 | char *cbuf; | 56 | char *cbuf; |
66 | size_t nsize; | 57 | size_t nsize; |
@@ -76,7 +67,6 @@ strata_estimator_write (const struct StrataEstimator *se, | |||
76 | GNUNET_free (cbuf); | 67 | GNUNET_free (cbuf); |
77 | } | 68 | } |
78 | } | 69 | } |
79 | #endif | ||
80 | return osize; | 70 | return osize; |
81 | } | 71 | } |
82 | 72 | ||
@@ -97,7 +87,6 @@ strata_estimator_read (const void *buf, | |||
97 | int is_compressed, | 87 | int is_compressed, |
98 | struct StrataEstimator *se) | 88 | struct StrataEstimator *se) |
99 | { | 89 | { |
100 | unsigned int i; | ||
101 | size_t osize; | 90 | size_t osize; |
102 | char *dbuf; | 91 | char *dbuf; |
103 | 92 | ||
@@ -124,7 +113,7 @@ strata_estimator_read (const void *buf, | |||
124 | return GNUNET_SYSERR; | 113 | return GNUNET_SYSERR; |
125 | } | 114 | } |
126 | 115 | ||
127 | for (i = 0; i < se->strata_count; i++) | 116 | for (unsigned int i = 0; i < se->strata_count; i++) |
128 | { | 117 | { |
129 | ibf_read_slice (buf, 0, se->ibf_size, se->strata[i]); | 118 | ibf_read_slice (buf, 0, se->ibf_size, se->strata[i]); |
130 | buf += se->ibf_size * IBF_BUCKET_SIZE; | 119 | buf += se->ibf_size * IBF_BUCKET_SIZE; |
@@ -145,11 +134,10 @@ strata_estimator_insert (struct StrataEstimator *se, | |||
145 | struct IBF_Key key) | 134 | struct IBF_Key key) |
146 | { | 135 | { |
147 | uint64_t v; | 136 | uint64_t v; |
148 | unsigned int i; | ||
149 | 137 | ||
150 | v = key.key_val; | 138 | v = key.key_val; |
151 | /* count trailing '1'-bits of v */ | 139 | /* count trailing '1'-bits of v */ |
152 | for (i = 0; v & 1; v >>= 1, i++) | 140 | for (unsigned int i = 0; v & 1; v >>= 1, i++) |
153 | /* empty */; | 141 | /* empty */; |
154 | ibf_insert (se->strata[i], key); | 142 | ibf_insert (se->strata[i], key); |
155 | } | 143 | } |
@@ -166,11 +154,10 @@ strata_estimator_remove (struct StrataEstimator *se, | |||
166 | struct IBF_Key key) | 154 | struct IBF_Key key) |
167 | { | 155 | { |
168 | uint64_t v; | 156 | uint64_t v; |
169 | unsigned int i; | ||
170 | 157 | ||
171 | v = key.key_val; | 158 | v = key.key_val; |
172 | /* count trailing '1'-bits of v */ | 159 | /* count trailing '1'-bits of v */ |
173 | for (i = 0; v & 1; v >>= 1, i++) | 160 | for (unsigned int i = 0; v & 1; v >>= 1, i++) |
174 | /* empty */; | 161 | /* empty */; |
175 | ibf_remove (se->strata[i], key); | 162 | ibf_remove (se->strata[i], key); |
176 | } | 163 | } |
@@ -190,22 +177,20 @@ strata_estimator_create (unsigned int strata_count, | |||
190 | uint8_t ibf_hashnum) | 177 | uint8_t ibf_hashnum) |
191 | { | 178 | { |
192 | struct StrataEstimator *se; | 179 | struct StrataEstimator *se; |
193 | unsigned int i; | ||
194 | unsigned int j; | ||
195 | 180 | ||
196 | se = GNUNET_new (struct StrataEstimator); | 181 | se = GNUNET_new (struct StrataEstimator); |
197 | se->strata_count = strata_count; | 182 | se->strata_count = strata_count; |
198 | se->ibf_size = ibf_size; | 183 | se->ibf_size = ibf_size; |
199 | se->strata = GNUNET_new_array (strata_count, | 184 | se->strata = GNUNET_new_array (strata_count, |
200 | struct InvertibleBloomFilter *); | 185 | struct InvertibleBloomFilter *); |
201 | for (i = 0; i < strata_count; i++) | 186 | for (unsigned int i = 0; i < strata_count; i++) |
202 | { | 187 | { |
203 | se->strata[i] = ibf_create (ibf_size, ibf_hashnum); | 188 | se->strata[i] = ibf_create (ibf_size, ibf_hashnum); |
204 | if (NULL == se->strata[i]) | 189 | if (NULL == se->strata[i]) |
205 | { | 190 | { |
206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 191 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
207 | "Failed to allocate memory for strata estimator\n"); | 192 | "Failed to allocate memory for strata estimator\n"); |
208 | for (j = 0; j < i; j++) | 193 | for (unsigned int j = 0; j < i; j++) |
209 | ibf_destroy (se->strata[i]); | 194 | ibf_destroy (se->strata[i]); |
210 | GNUNET_free (se); | 195 | GNUNET_free (se); |
211 | return NULL; | 196 | return NULL; |
@@ -273,14 +258,13 @@ struct StrataEstimator * | |||
273 | strata_estimator_dup (struct StrataEstimator *se) | 258 | strata_estimator_dup (struct StrataEstimator *se) |
274 | { | 259 | { |
275 | struct StrataEstimator *c; | 260 | struct StrataEstimator *c; |
276 | unsigned int i; | ||
277 | 261 | ||
278 | c = GNUNET_new (struct StrataEstimator); | 262 | c = GNUNET_new (struct StrataEstimator); |
279 | c->strata_count = se->strata_count; | 263 | c->strata_count = se->strata_count; |
280 | c->ibf_size = se->ibf_size; | 264 | c->ibf_size = se->ibf_size; |
281 | c->strata = GNUNET_new_array (se->strata_count, | 265 | c->strata = GNUNET_new_array (se->strata_count, |
282 | struct InvertibleBloomFilter *); | 266 | struct InvertibleBloomFilter *); |
283 | for (i = 0; i < se->strata_count; i++) | 267 | for (unsigned int i = 0; i < se->strata_count; i++) |
284 | c->strata[i] = ibf_dup (se->strata[i]); | 268 | c->strata[i] = ibf_dup (se->strata[i]); |
285 | return c; | 269 | return c; |
286 | } | 270 | } |
@@ -294,9 +278,7 @@ strata_estimator_dup (struct StrataEstimator *se) | |||
294 | void | 278 | void |
295 | strata_estimator_destroy (struct StrataEstimator *se) | 279 | strata_estimator_destroy (struct StrataEstimator *se) |
296 | { | 280 | { |
297 | unsigned int i; | 281 | for (unsigned int i = 0; i < se->strata_count; i++) |
298 | |||
299 | for (i = 0; i < se->strata_count; i++) | ||
300 | ibf_destroy (se->strata[i]); | 282 | ibf_destroy (se->strata[i]); |
301 | GNUNET_free (se->strata); | 283 | GNUNET_free (se->strata); |
302 | GNUNET_free (se); | 284 | GNUNET_free (se); |