diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-09-30 01:05:11 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-09-30 01:05:11 +0000 |
commit | 25e636d19d7220430cac2a4fbdda0cac09f0b15d (patch) | |
tree | e4324bfadf788047758202997b4424ba692aa296 /src/util | |
parent | c6c111abd1e7ffec4c5dacbb25baf9ed6b9da695 (diff) | |
download | gnunet-25e636d19d7220430cac2a4fbdda0cac09f0b15d.tar.gz gnunet-25e636d19d7220430cac2a4fbdda0cac09f0b15d.zip |
speed up BF tests
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/container_bloomfilter.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index a3152000b..7176bb1e3 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c | |||
@@ -316,10 +316,11 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size) | |||
316 | * @param cls closure | 316 | * @param cls closure |
317 | * @param bf the filter to manipulate | 317 | * @param bf the filter to manipulate |
318 | * @param bit the current bit | 318 | * @param bit the current bit |
319 | * @return GNUNET_YES to continue, GNUNET_NO to stop early | ||
319 | */ | 320 | */ |
320 | typedef void (*BitIterator) (void *cls, | 321 | typedef int (*BitIterator) (void *cls, |
321 | const struct GNUNET_CONTAINER_BloomFilter * bf, | 322 | const struct GNUNET_CONTAINER_BloomFilter * bf, |
322 | unsigned int bit); | 323 | unsigned int bit); |
323 | 324 | ||
324 | /** | 325 | /** |
325 | * Call an iterator for each bit that the bloomfilter | 326 | * Call an iterator for each bit that the bloomfilter |
@@ -336,7 +337,7 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
336 | { | 337 | { |
337 | GNUNET_HashCode tmp[2]; | 338 | GNUNET_HashCode tmp[2]; |
338 | int bitCount; | 339 | int bitCount; |
339 | int round; | 340 | unsigned int round; |
340 | unsigned int slot = 0; | 341 | unsigned int slot = 0; |
341 | 342 | ||
342 | bitCount = bf->addressesPerElement; | 343 | bitCount = bf->addressesPerElement; |
@@ -346,9 +347,11 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
346 | { | 347 | { |
347 | while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) | 348 | while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) |
348 | { | 349 | { |
349 | callback (arg, bf, | 350 | if (GNUNET_YES != |
350 | (((uint32_t *) & tmp[round & 1])[slot]) & | 351 | callback (arg, bf, |
351 | ((bf->bitArraySize * 8) - 1)); | 352 | (((uint32_t *) & tmp[round & 1])[slot]) & |
353 | ((bf->bitArraySize * 8) - 1))) | ||
354 | return; | ||
352 | slot++; | 355 | slot++; |
353 | bitCount--; | 356 | bitCount--; |
354 | if (bitCount == 0) | 357 | if (bitCount == 0) |
@@ -370,14 +373,16 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
370 | * @param cls pointer to writeable form of bf | 373 | * @param cls pointer to writeable form of bf |
371 | * @param bf the filter to manipulate | 374 | * @param bf the filter to manipulate |
372 | * @param bit the bit to increment | 375 | * @param bit the bit to increment |
376 | * @return GNUNET_YES | ||
373 | */ | 377 | */ |
374 | static void | 378 | static int |
375 | incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | 379 | incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, |
376 | unsigned int bit) | 380 | unsigned int bit) |
377 | { | 381 | { |
378 | struct GNUNET_CONTAINER_BloomFilter *b = cls; | 382 | struct GNUNET_CONTAINER_BloomFilter *b = cls; |
379 | 383 | ||
380 | incrementBit (b->bitArray, bit, bf->fh); | 384 | incrementBit (b->bitArray, bit, bf->fh); |
385 | return GNUNET_YES; | ||
381 | } | 386 | } |
382 | 387 | ||
383 | /** | 388 | /** |
@@ -386,14 +391,16 @@ incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
386 | * @param cls pointer to writeable form of bf | 391 | * @param cls pointer to writeable form of bf |
387 | * @param bf the filter to manipulate | 392 | * @param bf the filter to manipulate |
388 | * @param bit the bit to decrement | 393 | * @param bit the bit to decrement |
394 | * @return GNUNET_YES | ||
389 | */ | 395 | */ |
390 | static void | 396 | static int |
391 | decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | 397 | decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, |
392 | unsigned int bit) | 398 | unsigned int bit) |
393 | { | 399 | { |
394 | struct GNUNET_CONTAINER_BloomFilter *b = cls; | 400 | struct GNUNET_CONTAINER_BloomFilter *b = cls; |
395 | 401 | ||
396 | decrementBit (b->bitArray, bit, bf->fh); | 402 | decrementBit (b->bitArray, bit, bf->fh); |
403 | return GNUNET_YES; | ||
397 | } | 404 | } |
398 | 405 | ||
399 | /** | 406 | /** |
@@ -402,15 +409,20 @@ decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
402 | * @param cls pointer set to GNUNET_NO if bit is not set | 409 | * @param cls pointer set to GNUNET_NO if bit is not set |
403 | * @param bf the filter | 410 | * @param bf the filter |
404 | * @param bit the bit to test | 411 | * @param bit the bit to test |
412 | * @return YES if the bit is set, NO if not | ||
405 | */ | 413 | */ |
406 | static void | 414 | static int |
407 | testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | 415 | testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, |
408 | unsigned int bit) | 416 | unsigned int bit) |
409 | { | 417 | { |
410 | int *arg = cls; | 418 | int *arg = cls; |
411 | 419 | ||
412 | if (GNUNET_NO == testBit (bf->bitArray, bit)) | 420 | if (GNUNET_NO == testBit (bf->bitArray, bit)) |
421 | { | ||
413 | *arg = GNUNET_NO; | 422 | *arg = GNUNET_NO; |
423 | return GNUNET_NO; | ||
424 | } | ||
425 | return GNUNET_YES; | ||
414 | } | 426 | } |
415 | 427 | ||
416 | /* *********************** INTERFACE **************** */ | 428 | /* *********************** INTERFACE **************** */ |