aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-01-15 20:18:09 +0100
committerChristian Grothoff <christian@grothoff.org>2021-01-15 20:18:09 +0100
commit184f6b151c2087a9870b32eab45b101ba79973d9 (patch)
tree992a81bf8843e45b4892c1b9b0f1d834027b62e0
parente53d2c28acad7e33945e41daed5aac6c01012836 (diff)
downloadgnunet-184f6b151c2087a9870b32eab45b101ba79973d9.tar.gz
gnunet-184f6b151c2087a9870b32eab45b101ba79973d9.zip
indentation and style fixes
-rw-r--r--src/hello/gnunet-hello.c2
-rw-r--r--src/setu/ibf.c85
2 files changed, 48 insertions, 39 deletions
diff --git a/src/hello/gnunet-hello.c b/src/hello/gnunet-hello.c
index b3f48322b..1f110ac18 100644
--- a/src/hello/gnunet-hello.c
+++ b/src/hello/gnunet-hello.c
@@ -51,7 +51,7 @@ static int address_count;
51 51
52 52
53/** 53/**
54 * Add the given address with infinit expiration to the buffer. 54 * Add the given address with infinite expiration to the buffer.
55 * 55 *
56 * @param cls closure 56 * @param cls closure
57 * @param address address to add 57 * @param address address to add
diff --git a/src/setu/ibf.c b/src/setu/ibf.c
index 1532afceb..f079722bd 100644
--- a/src/setu/ibf.c
+++ b/src/setu/ibf.c
@@ -164,7 +164,8 @@ ibf_insert_into (struct InvertibleBloomFilter *ibf,
164 * @param key the element's hash code 164 * @param key the element's hash code
165 */ 165 */
166void 166void
167ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key) 167ibf_insert (struct InvertibleBloomFilter *ibf,
168 struct IBF_Key key)
168{ 169{
169 int buckets[ibf->hash_num]; 170 int buckets[ibf->hash_num];
170 171
@@ -181,7 +182,8 @@ ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key)
181 * @param key the element's hash code 182 * @param key the element's hash code
182 */ 183 */
183void 184void
184ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key) 185ibf_remove (struct InvertibleBloomFilter *ibf,
186 struct IBF_Key key)
185{ 187{
186 int buckets[ibf->hash_num]; 188 int buckets[ibf->hash_num];
187 189
@@ -197,9 +199,7 @@ ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key)
197static int 199static int
198ibf_is_empty (struct InvertibleBloomFilter *ibf) 200ibf_is_empty (struct InvertibleBloomFilter *ibf)
199{ 201{
200 int i; 202 for (uint32_t i = 0; i < ibf->size; i++)
201
202 for (i = 0; i < ibf->size; i++)
203 { 203 {
204 if (0 != ibf->count[i].count_val) 204 if (0 != ibf->count[i].count_val)
205 return GNUNET_NO; 205 return GNUNET_NO;
@@ -220,27 +220,25 @@ ibf_is_empty (struct InvertibleBloomFilter *ibf)
220 * A negative sign indicates that the element was recovered 220 * A negative sign indicates that the element was recovered
221 * resides in an IBF that was previously subtracted from. 221 * resides in an IBF that was previously subtracted from.
222 * @param ret_id receives the hash code of the decoded element, if successful 222 * @param ret_id receives the hash code of the decoded element, if successful
223 * @return GNUNET_YES if decoding an element was successful, 223 * @return #GNUNET_YES if decoding an element was successful,
224 * GNUNET_NO if the IBF is empty, 224 * #GNUNET_NO if the IBF is empty,
225 * GNUNET_SYSERR if the decoding has failed 225 * #GNUNET_SYSERR if the decoding has failed
226 */ 226 */
227int 227int
228ibf_decode (struct InvertibleBloomFilter *ibf, 228ibf_decode (struct InvertibleBloomFilter *ibf,
229 int *ret_side, struct IBF_Key *ret_id) 229 int *ret_side,
230 struct IBF_Key *ret_id)
230{ 231{
231 struct IBF_KeyHash hash; 232 struct IBF_KeyHash hash;
232 int i;
233 int buckets[ibf->hash_num]; 233 int buckets[ibf->hash_num];
234 234
235 GNUNET_assert (NULL != ibf); 235 for (uint32_t i = 0; i < ibf->size; i++)
236
237 for (i = 0; i < ibf->size; i++)
238 { 236 {
239 int j;
240 int hit; 237 int hit;
241 238
242 /* we can only decode from pure buckets */ 239 /* we can only decode from pure buckets */
243 if ((1 != ibf->count[i].count_val) && (-1 != ibf->count[i].count_val)) 240 if ( (1 != ibf->count[i].count_val) &&
241 (-1 != ibf->count[i].count_val) )
244 continue; 242 continue;
245 243
246 hash.key_hash_val = IBF_KEY_HASH_VAL (ibf->key_sum[i]); 244 hash.key_hash_val = IBF_KEY_HASH_VAL (ibf->key_sum[i]);
@@ -253,7 +251,7 @@ ibf_decode (struct InvertibleBloomFilter *ibf,
253 * if not, the key hash was subject to collision */ 251 * if not, the key hash was subject to collision */
254 hit = GNUNET_NO; 252 hit = GNUNET_NO;
255 ibf_get_indices (ibf, ibf->key_sum[i], buckets); 253 ibf_get_indices (ibf, ibf->key_sum[i], buckets);
256 for (j = 0; j < ibf->hash_num; j++) 254 for (int j = 0; j < ibf->hash_num; j++)
257 if (buckets[j] == i) 255 if (buckets[j] == i)
258 hit = GNUNET_YES; 256 hit = GNUNET_YES;
259 257
@@ -287,7 +285,8 @@ ibf_decode (struct InvertibleBloomFilter *ibf,
287 * @param buf buffer to write the data to 285 * @param buf buffer to write the data to
288 */ 286 */
289void 287void
290ibf_write_slice (const struct InvertibleBloomFilter *ibf, uint32_t start, 288ibf_write_slice (const struct InvertibleBloomFilter *ibf,
289 uint32_t start,
291 uint32_t count, void *buf) 290 uint32_t count, void *buf)
292{ 291{
293 struct IBF_Key *key_dst; 292 struct IBF_Key *key_dst;
@@ -298,16 +297,21 @@ ibf_write_slice (const struct InvertibleBloomFilter *ibf, uint32_t start,
298 297
299 /* copy keys */ 298 /* copy keys */
300 key_dst = (struct IBF_Key *) buf; 299 key_dst = (struct IBF_Key *) buf;
301 GNUNET_memcpy (key_dst, ibf->key_sum + start, count * sizeof *key_dst); 300 GNUNET_memcpy (key_dst,
301 ibf->key_sum + start,
302 count * sizeof *key_dst);
302 key_dst += count; 303 key_dst += count;
303 /* copy key hashes */ 304 /* copy key hashes */
304 key_hash_dst = (struct IBF_KeyHash *) key_dst; 305 key_hash_dst = (struct IBF_KeyHash *) key_dst;
305 GNUNET_memcpy (key_hash_dst, ibf->key_hash_sum + start, count 306 GNUNET_memcpy (key_hash_dst,
306 * sizeof *key_hash_dst); 307 ibf->key_hash_sum + start,
308 count * sizeof *key_hash_dst);
307 key_hash_dst += count; 309 key_hash_dst += count;
308 /* copy counts */ 310 /* copy counts */
309 count_dst = (struct IBF_Count *) key_hash_dst; 311 count_dst = (struct IBF_Count *) key_hash_dst;
310 GNUNET_memcpy (count_dst, ibf->count + start, count * sizeof *count_dst); 312 GNUNET_memcpy (count_dst,
313 ibf->count + start,
314 count * sizeof *count_dst);
311} 315}
312 316
313 317
@@ -320,8 +324,10 @@ ibf_write_slice (const struct InvertibleBloomFilter *ibf, uint32_t start,
320 * @param ibf the ibf to read from 324 * @param ibf the ibf to read from
321 */ 325 */
322void 326void
323ibf_read_slice (const void *buf, uint32_t start, uint32_t count, struct 327ibf_read_slice (const void *buf,
324 InvertibleBloomFilter *ibf) 328 uint32_t start,
329 uint32_t count,
330 struct InvertibleBloomFilter *ibf)
325{ 331{
326 struct IBF_Key *key_src; 332 struct IBF_Key *key_src;
327 struct IBF_KeyHash *key_hash_src; 333 struct IBF_KeyHash *key_hash_src;
@@ -332,16 +338,21 @@ ibf_read_slice (const void *buf, uint32_t start, uint32_t count, struct
332 338
333 /* copy keys */ 339 /* copy keys */
334 key_src = (struct IBF_Key *) buf; 340 key_src = (struct IBF_Key *) buf;
335 GNUNET_memcpy (ibf->key_sum + start, key_src, count * sizeof *key_src); 341 GNUNET_memcpy (ibf->key_sum + start,
342 key_src,
343 count * sizeof *key_src);
336 key_src += count; 344 key_src += count;
337 /* copy key hashes */ 345 /* copy key hashes */
338 key_hash_src = (struct IBF_KeyHash *) key_src; 346 key_hash_src = (struct IBF_KeyHash *) key_src;
339 GNUNET_memcpy (ibf->key_hash_sum + start, key_hash_src, count 347 GNUNET_memcpy (ibf->key_hash_sum + start,
340 * sizeof *key_hash_src); 348 key_hash_src,
349 count * sizeof *key_hash_src);
341 key_hash_src += count; 350 key_hash_src += count;
342 /* copy counts */ 351 /* copy counts */
343 count_src = (struct IBF_Count *) key_hash_src; 352 count_src = (struct IBF_Count *) key_hash_src;
344 GNUNET_memcpy (ibf->count + start, count_src, count * sizeof *count_src); 353 GNUNET_memcpy (ibf->count + start,
354 count_src,
355 count * sizeof *count_src);
345} 356}
346 357
347 358
@@ -353,15 +364,13 @@ ibf_read_slice (const void *buf, uint32_t start, uint32_t count, struct
353 * @param ibf2 IBF that will be subtracted from ibf1 364 * @param ibf2 IBF that will be subtracted from ibf1
354 */ 365 */
355void 366void
356ibf_subtract (struct InvertibleBloomFilter *ibf1, const struct 367ibf_subtract (struct InvertibleBloomFilter *ibf1,
357 InvertibleBloomFilter *ibf2) 368 const struct InvertibleBloomFilter *ibf2)
358{ 369{
359 int i;
360
361 GNUNET_assert (ibf1->size == ibf2->size); 370 GNUNET_assert (ibf1->size == ibf2->size);
362 GNUNET_assert (ibf1->hash_num == ibf2->hash_num); 371 GNUNET_assert (ibf1->hash_num == ibf2->hash_num);
363 372
364 for (i = 0; i < ibf1->size; i++) 373 for (uint32_t i = 0; i < ibf1->size; i++)
365 { 374 {
366 ibf1->count[i].count_val -= ibf2->count[i].count_val; 375 ibf1->count[i].count_val -= ibf2->count[i].count_val;
367 ibf1->key_hash_sum[i].key_hash_val ^= ibf2->key_hash_sum[i].key_hash_val; 376 ibf1->key_hash_sum[i].key_hash_val ^= ibf2->key_hash_sum[i].key_hash_val;
@@ -383,12 +392,12 @@ ibf_dup (const struct InvertibleBloomFilter *ibf)
383 copy = GNUNET_malloc (sizeof *copy); 392 copy = GNUNET_malloc (sizeof *copy);
384 copy->hash_num = ibf->hash_num; 393 copy->hash_num = ibf->hash_num;
385 copy->size = ibf->size; 394 copy->size = ibf->size;
386 copy->key_hash_sum = GNUNET_memdup (ibf->key_hash_sum, ibf->size 395 copy->key_hash_sum = GNUNET_memdup (ibf->key_hash_sum,
387 * sizeof(struct IBF_KeyHash)); 396 ibf->size * sizeof(struct IBF_KeyHash));
388 copy->key_sum = GNUNET_memdup (ibf->key_sum, ibf->size * sizeof(struct 397 copy->key_sum = GNUNET_memdup (ibf->key_sum,
389 IBF_Key)); 398 ibf->size * sizeof(struct IBF_Key));
390 copy->count = GNUNET_memdup (ibf->count, ibf->size * sizeof(struct 399 copy->count = GNUNET_memdup (ibf->count,
391 IBF_Count)); 400 ibf->size * sizeof(struct IBF_Count));
392 return copy; 401 return copy;
393} 402}
394 403