diff options
author | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2011-09-30 01:05:11 +0000 |
---|---|---|
committer | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2011-09-30 01:05:11 +0000 |
commit | fc9fe25ec3a60eaf409152042ef4c6b108ef83f9 (patch) | |
tree | e4324bfadf788047758202997b4424ba692aa296 /src/util/container_bloomfilter.c | |
parent | a3e30a76cd051d9e90fbbe290edbd7d0f0391ece (diff) |
speed up BF tests
git-svn-id: https://gnunet.org/svn/gnunet@17130 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/util/container_bloomfilter.c')
-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 a3152000bc..7176bb1e3e 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) * @param cls closure * @param bf the filter to manipulate * @param bit the current bit + * @return GNUNET_YES to continue, GNUNET_NO to stop early */ -typedef void (*BitIterator) (void *cls, - const struct GNUNET_CONTAINER_BloomFilter * bf, - unsigned int bit); +typedef int (*BitIterator) (void *cls, + const struct GNUNET_CONTAINER_BloomFilter * bf, + unsigned int bit); /** * Call an iterator for each bit that the bloomfilter @@ -336,7 +337,7 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, { GNUNET_HashCode tmp[2]; int bitCount; - int round; + unsigned int round; unsigned int slot = 0; bitCount = bf->addressesPerElement; @@ -346,9 +347,11 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, { while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) { - callback (arg, bf, - (((uint32_t *) & tmp[round & 1])[slot]) & - ((bf->bitArraySize * 8) - 1)); + if (GNUNET_YES != + callback (arg, bf, + (((uint32_t *) & tmp[round & 1])[slot]) & + ((bf->bitArraySize * 8) - 1))) + return; slot++; bitCount--; if (bitCount == 0) @@ -370,14 +373,16 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, * @param cls pointer to writeable form of bf * @param bf the filter to manipulate * @param bit the bit to increment + * @return GNUNET_YES */ -static void +static int incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) { struct GNUNET_CONTAINER_BloomFilter *b = cls; incrementBit (b->bitArray, bit, bf->fh); + return GNUNET_YES; } /** @@ -386,14 +391,16 @@ incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, * @param cls pointer to writeable form of bf * @param bf the filter to manipulate * @param bit the bit to decrement + * @return GNUNET_YES */ -static void +static int decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) { struct GNUNET_CONTAINER_BloomFilter *b = cls; decrementBit (b->bitArray, bit, bf->fh); + return GNUNET_YES; } /** @@ -402,15 +409,20 @@ decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, * @param cls pointer set to GNUNET_NO if bit is not set * @param bf the filter * @param bit the bit to test + * @return YES if the bit is set, NO if not */ -static void +static int testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) { int *arg = cls; if (GNUNET_NO == testBit (bf->bitArray, bit)) + { *arg = GNUNET_NO; + return GNUNET_NO; + } + return GNUNET_YES; } /* *********************** INTERFACE **************** */ |