diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-11 09:43:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-11 09:43:04 +0000 |
commit | d9d94d0e53d26af75ec8241383d166544ebd79f3 (patch) | |
tree | 9080b73624389403a198257fe0547bb4634e64d2 /src/util/container_bloomfilter.c | |
parent | 2d792ee2e9cc0c993b8907e2c8edb0c2b8465343 (diff) | |
download | gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.tar.gz gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.zip |
converting to GNUNET_LOG_from*
Diffstat (limited to 'src/util/container_bloomfilter.c')
-rw-r--r-- | src/util/container_bloomfilter.c | 263 |
1 files changed, 135 insertions, 128 deletions
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index b7be764b5..a33b619ff 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c | |||
@@ -44,6 +44,12 @@ | |||
44 | #include "gnunet_container_lib.h" | 44 | #include "gnunet_container_lib.h" |
45 | #include "gnunet_disk_lib.h" | 45 | #include "gnunet_disk_lib.h" |
46 | 46 | ||
47 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | ||
48 | |||
49 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall) | ||
50 | |||
51 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) | ||
52 | |||
47 | struct GNUNET_CONTAINER_BloomFilter | 53 | struct GNUNET_CONTAINER_BloomFilter |
48 | { | 54 | { |
49 | 55 | ||
@@ -83,8 +89,8 @@ struct GNUNET_CONTAINER_BloomFilter | |||
83 | * @return number of bytes used for the data of the bloom filter | 89 | * @return number of bytes used for the data of the bloom filter |
84 | */ | 90 | */ |
85 | size_t | 91 | size_t |
86 | GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter | 92 | GNUNET_CONTAINER_bloomfilter_get_size (const struct |
87 | *bf) | 93 | GNUNET_CONTAINER_BloomFilter *bf) |
88 | { | 94 | { |
89 | if (bf == NULL) | 95 | if (bf == NULL) |
90 | return 0; | 96 | return 0; |
@@ -100,10 +106,10 @@ GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter | |||
100 | */ | 106 | */ |
101 | struct GNUNET_CONTAINER_BloomFilter * | 107 | struct GNUNET_CONTAINER_BloomFilter * |
102 | GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter | 108 | GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter |
103 | *bf) | 109 | *bf) |
104 | { | 110 | { |
105 | return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize, | 111 | return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize, |
106 | bf->addressesPerElement); | 112 | bf->addressesPerElement); |
107 | } | 113 | } |
108 | 114 | ||
109 | 115 | ||
@@ -175,7 +181,7 @@ testBit (char *bitArray, unsigned int bitIdx) | |||
175 | */ | 181 | */ |
176 | static void | 182 | static void |
177 | incrementBit (char *bitArray, unsigned int bitIdx, | 183 | incrementBit (char *bitArray, unsigned int bitIdx, |
178 | const struct GNUNET_DISK_FileHandle *fh) | 184 | const struct GNUNET_DISK_FileHandle *fh) |
179 | { | 185 | { |
180 | off_t fileSlot; | 186 | off_t fileSlot; |
181 | unsigned char value; | 187 | unsigned char value; |
@@ -191,25 +197,25 @@ incrementBit (char *bitArray, unsigned int bitIdx, | |||
191 | targetLoc = bitIdx % 2; | 197 | targetLoc = bitIdx % 2; |
192 | 198 | ||
193 | GNUNET_assert (fileSlot == | 199 | GNUNET_assert (fileSlot == |
194 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); | 200 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); |
195 | if (1 != GNUNET_DISK_file_read (fh, &value, 1)) | 201 | if (1 != GNUNET_DISK_file_read (fh, &value, 1)) |
196 | value = 0; | 202 | value = 0; |
197 | low = value & 0xF; | 203 | low = value & 0xF; |
198 | high = (value & (~0xF)) >> 4; | 204 | high = (value & (~0xF)) >> 4; |
199 | 205 | ||
200 | if (targetLoc == 0) | 206 | if (targetLoc == 0) |
201 | { | 207 | { |
202 | if (low < 0xF) | 208 | if (low < 0xF) |
203 | low++; | 209 | low++; |
204 | } | 210 | } |
205 | else | 211 | else |
206 | { | 212 | { |
207 | if (high < 0xF) | 213 | if (high < 0xF) |
208 | high++; | 214 | high++; |
209 | } | 215 | } |
210 | value = ((high << 4) | low); | 216 | value = ((high << 4) | low); |
211 | GNUNET_assert (fileSlot == | 217 | GNUNET_assert (fileSlot == |
212 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); | 218 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); |
213 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); | 219 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); |
214 | } | 220 | } |
215 | 221 | ||
@@ -223,7 +229,7 @@ incrementBit (char *bitArray, unsigned int bitIdx, | |||
223 | */ | 229 | */ |
224 | static void | 230 | static void |
225 | decrementBit (char *bitArray, unsigned int bitIdx, | 231 | decrementBit (char *bitArray, unsigned int bitIdx, |
226 | const struct GNUNET_DISK_FileHandle *fh) | 232 | const struct GNUNET_DISK_FileHandle *fh) |
227 | { | 233 | { |
228 | off_t fileSlot; | 234 | off_t fileSlot; |
229 | unsigned char value; | 235 | unsigned char value; |
@@ -232,7 +238,7 @@ decrementBit (char *bitArray, unsigned int bitIdx, | |||
232 | unsigned int targetLoc; | 238 | unsigned int targetLoc; |
233 | 239 | ||
234 | if (GNUNET_DISK_handle_invalid (fh)) | 240 | if (GNUNET_DISK_handle_invalid (fh)) |
235 | return; /* cannot decrement! */ | 241 | return; /* cannot decrement! */ |
236 | /* Each char slot in the counter file holds two 4 bit counters */ | 242 | /* Each char slot in the counter file holds two 4 bit counters */ |
237 | fileSlot = bitIdx / 2; | 243 | fileSlot = bitIdx / 2; |
238 | targetLoc = bitIdx % 2; | 244 | targetLoc = bitIdx % 2; |
@@ -244,23 +250,23 @@ decrementBit (char *bitArray, unsigned int bitIdx, | |||
244 | 250 | ||
245 | /* decrement, but once we have reached the max, never go back! */ | 251 | /* decrement, but once we have reached the max, never go back! */ |
246 | if (targetLoc == 0) | 252 | if (targetLoc == 0) |
247 | { | ||
248 | if ((low > 0) && (low < 0xF)) | ||
249 | low--; | ||
250 | if (low == 0) | ||
251 | { | 253 | { |
252 | clearBit (bitArray, bitIdx); | 254 | if ((low > 0) && (low < 0xF)) |
255 | low--; | ||
256 | if (low == 0) | ||
257 | { | ||
258 | clearBit (bitArray, bitIdx); | ||
259 | } | ||
253 | } | 260 | } |
254 | } | ||
255 | else | 261 | else |
256 | { | ||
257 | if ((high > 0) && (high < 0xF)) | ||
258 | high--; | ||
259 | if (high == 0) | ||
260 | { | 262 | { |
261 | clearBit (bitArray, bitIdx); | 263 | if ((high > 0) && (high < 0xF)) |
264 | high--; | ||
265 | if (high == 0) | ||
266 | { | ||
267 | clearBit (bitArray, bitIdx); | ||
268 | } | ||
262 | } | 269 | } |
263 | } | ||
264 | value = ((high << 4) | low); | 270 | value = ((high << 4) | low); |
265 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET); | 271 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET); |
266 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); | 272 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); |
@@ -289,19 +295,19 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size) | |||
289 | GNUNET_DISK_file_seek (fh, 0, GNUNET_DISK_SEEK_SET); | 295 | GNUNET_DISK_file_seek (fh, 0, GNUNET_DISK_SEEK_SET); |
290 | 296 | ||
291 | while (bytesleft > 0) | 297 | while (bytesleft > 0) |
292 | { | ||
293 | if (bytesleft > BUFFSIZE) | ||
294 | { | 298 | { |
295 | res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE); | 299 | if (bytesleft > BUFFSIZE) |
296 | bytesleft -= BUFFSIZE; | 300 | { |
301 | res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE); | ||
302 | bytesleft -= BUFFSIZE; | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | res = GNUNET_DISK_file_write (fh, buffer, bytesleft); | ||
307 | bytesleft = 0; | ||
308 | } | ||
309 | GNUNET_assert (res != GNUNET_SYSERR); | ||
297 | } | 310 | } |
298 | else | ||
299 | { | ||
300 | res = GNUNET_DISK_file_write (fh, buffer, bytesleft); | ||
301 | bytesleft = 0; | ||
302 | } | ||
303 | GNUNET_assert (res != GNUNET_SYSERR); | ||
304 | } | ||
305 | GNUNET_free (buffer); | 311 | GNUNET_free (buffer); |
306 | return GNUNET_OK; | 312 | return GNUNET_OK; |
307 | } | 313 | } |
@@ -334,7 +340,7 @@ typedef int (*BitIterator) (void *cls, | |||
334 | */ | 340 | */ |
335 | static void | 341 | static void |
336 | iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, | 342 | iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, |
337 | BitIterator callback, void *arg, const GNUNET_HashCode * key) | 343 | BitIterator callback, void *arg, const GNUNET_HashCode * key) |
338 | { | 344 | { |
339 | GNUNET_HashCode tmp[2]; | 345 | GNUNET_HashCode tmp[2]; |
340 | int bitCount; | 346 | int bitCount; |
@@ -345,27 +351,27 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
345 | tmp[0] = *key; | 351 | tmp[0] = *key; |
346 | round = 0; | 352 | round = 0; |
347 | while (bitCount > 0) | 353 | while (bitCount > 0) |
348 | { | ||
349 | while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) | ||
350 | { | ||
351 | if (GNUNET_YES != | ||
352 | callback (arg, bf, | ||
353 | (((uint32_t *) & tmp[round & 1])[slot]) & | ||
354 | ((bf->bitArraySize * 8) - 1))) | ||
355 | return; | ||
356 | slot++; | ||
357 | bitCount--; | ||
358 | if (bitCount == 0) | ||
359 | break; | ||
360 | } | ||
361 | if (bitCount > 0) | ||
362 | { | 354 | { |
363 | GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode), | 355 | while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) |
364 | &tmp[(round + 1) & 1]); | 356 | { |
365 | round++; | 357 | if (GNUNET_YES != |
366 | slot = 0; | 358 | callback (arg, bf, |
359 | (((uint32_t *) & tmp[round & 1])[slot]) & | ||
360 | ((bf->bitArraySize * 8) - 1))) | ||
361 | return; | ||
362 | slot++; | ||
363 | bitCount--; | ||
364 | if (bitCount == 0) | ||
365 | break; | ||
366 | } | ||
367 | if (bitCount > 0) | ||
368 | { | ||
369 | GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode), | ||
370 | &tmp[(round + 1) & 1]); | ||
371 | round++; | ||
372 | slot = 0; | ||
373 | } | ||
367 | } | 374 | } |
368 | } | ||
369 | } | 375 | } |
370 | 376 | ||
371 | 377 | ||
@@ -378,8 +384,9 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
378 | * @return GNUNET_YES | 384 | * @return GNUNET_YES |
379 | */ | 385 | */ |
380 | static int | 386 | static int |
381 | incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | 387 | incrementBitCallback (void *cls, |
382 | unsigned int bit) | 388 | const struct GNUNET_CONTAINER_BloomFilter *bf, |
389 | unsigned int bit) | ||
383 | { | 390 | { |
384 | struct GNUNET_CONTAINER_BloomFilter *b = cls; | 391 | struct GNUNET_CONTAINER_BloomFilter *b = cls; |
385 | 392 | ||
@@ -397,8 +404,9 @@ incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
397 | * @return GNUNET_YES | 404 | * @return GNUNET_YES |
398 | */ | 405 | */ |
399 | static int | 406 | static int |
400 | decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | 407 | decrementBitCallback (void *cls, |
401 | unsigned int bit) | 408 | const struct GNUNET_CONTAINER_BloomFilter *bf, |
409 | unsigned int bit) | ||
402 | { | 410 | { |
403 | struct GNUNET_CONTAINER_BloomFilter *b = cls; | 411 | struct GNUNET_CONTAINER_BloomFilter *b = cls; |
404 | 412 | ||
@@ -417,15 +425,15 @@ decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
417 | */ | 425 | */ |
418 | static int | 426 | static int |
419 | testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | 427 | testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, |
420 | unsigned int bit) | 428 | unsigned int bit) |
421 | { | 429 | { |
422 | int *arg = cls; | 430 | int *arg = cls; |
423 | 431 | ||
424 | if (GNUNET_NO == testBit (bf->bitArray, bit)) | 432 | if (GNUNET_NO == testBit (bf->bitArray, bit)) |
425 | { | 433 | { |
426 | *arg = GNUNET_NO; | 434 | *arg = GNUNET_NO; |
427 | return GNUNET_NO; | 435 | return GNUNET_NO; |
428 | } | 436 | } |
429 | return GNUNET_YES; | 437 | return GNUNET_YES; |
430 | } | 438 | } |
431 | 439 | ||
@@ -443,7 +451,7 @@ testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
443 | */ | 451 | */ |
444 | struct GNUNET_CONTAINER_BloomFilter * | 452 | struct GNUNET_CONTAINER_BloomFilter * |
445 | GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | 453 | GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, |
446 | unsigned int k) | 454 | unsigned int k) |
447 | { | 455 | { |
448 | struct GNUNET_CONTAINER_BloomFilter *bf; | 456 | struct GNUNET_CONTAINER_BloomFilter *bf; |
449 | char *rbuff; | 457 | char *rbuff; |
@@ -459,32 +467,32 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
459 | ui = 1; | 467 | ui = 1; |
460 | while (ui < size) | 468 | while (ui < size) |
461 | ui *= 2; | 469 | ui *= 2; |
462 | size = ui; /* make sure it's a power of 2 */ | 470 | size = ui; /* make sure it's a power of 2 */ |
463 | 471 | ||
464 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); | 472 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); |
465 | /* Try to open a bloomfilter file */ | 473 | /* Try to open a bloomfilter file */ |
466 | bf->fh = | 474 | bf->fh = |
467 | GNUNET_DISK_file_open (filename, | 475 | GNUNET_DISK_file_open (filename, |
468 | GNUNET_DISK_OPEN_READWRITE | | 476 | GNUNET_DISK_OPEN_READWRITE | |
469 | GNUNET_DISK_OPEN_CREATE, | 477 | GNUNET_DISK_OPEN_CREATE, |
470 | GNUNET_DISK_PERM_USER_READ | | 478 | GNUNET_DISK_PERM_USER_READ | |
471 | GNUNET_DISK_PERM_USER_WRITE); | 479 | GNUNET_DISK_PERM_USER_WRITE); |
472 | if (NULL == bf->fh) | 480 | if (NULL == bf->fh) |
473 | { | 481 | { |
474 | GNUNET_free (bf); | 482 | GNUNET_free (bf); |
475 | return NULL; | 483 | return NULL; |
476 | } | 484 | } |
477 | bf->filename = GNUNET_strdup (filename); | 485 | bf->filename = GNUNET_strdup (filename); |
478 | /* Alloc block */ | 486 | /* Alloc block */ |
479 | bf->bitArray = GNUNET_malloc_large (size); | 487 | bf->bitArray = GNUNET_malloc_large (size); |
480 | if (bf->bitArray == NULL) | 488 | if (bf->bitArray == NULL) |
481 | { | 489 | { |
482 | if (bf->fh != NULL) | 490 | if (bf->fh != NULL) |
483 | GNUNET_DISK_file_close (bf->fh); | 491 | GNUNET_DISK_file_close (bf->fh); |
484 | GNUNET_free (bf->filename); | 492 | GNUNET_free (bf->filename); |
485 | GNUNET_free (bf); | 493 | GNUNET_free (bf); |
486 | return NULL; | 494 | return NULL; |
487 | } | 495 | } |
488 | bf->bitArraySize = size; | 496 | bf->bitArraySize = size; |
489 | bf->addressesPerElement = k; | 497 | bf->addressesPerElement = k; |
490 | memset (bf->bitArray, 0, bf->bitArraySize); | 498 | memset (bf->bitArray, 0, bf->bitArraySize); |
@@ -493,28 +501,27 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
493 | rbuff = GNUNET_malloc (BUFFSIZE); | 501 | rbuff = GNUNET_malloc (BUFFSIZE); |
494 | pos = 0; | 502 | pos = 0; |
495 | while (pos < size * 8) | 503 | while (pos < size * 8) |
496 | { | ||
497 | int res; | ||
498 | |||
499 | res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); | ||
500 | if (res == -1) | ||
501 | { | ||
502 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", | ||
503 | bf->filename); | ||
504 | } | ||
505 | if (res == 0) | ||
506 | break; /* is ok! we just did not use that many bits yet */ | ||
507 | for (i = 0; i < res; i++) | ||
508 | { | 504 | { |
509 | if ((rbuff[i] & 0x0F) != 0) | 505 | int res; |
510 | setBit (bf->bitArray, pos + i * 2); | 506 | |
511 | if ((rbuff[i] & 0xF0) != 0) | 507 | res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); |
512 | setBit (bf->bitArray, pos + i * 2 + 1); | 508 | if (res == -1) |
509 | { | ||
510 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename); | ||
511 | } | ||
512 | if (res == 0) | ||
513 | break; /* is ok! we just did not use that many bits yet */ | ||
514 | for (i = 0; i < res; i++) | ||
515 | { | ||
516 | if ((rbuff[i] & 0x0F) != 0) | ||
517 | setBit (bf->bitArray, pos + i * 2); | ||
518 | if ((rbuff[i] & 0xF0) != 0) | ||
519 | setBit (bf->bitArray, pos + i * 2 + 1); | ||
520 | } | ||
521 | if (res < BUFFSIZE) | ||
522 | break; | ||
523 | pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */ | ||
513 | } | 524 | } |
514 | if (res < BUFFSIZE) | ||
515 | break; | ||
516 | pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */ | ||
517 | } | ||
518 | GNUNET_free (rbuff); | 525 | GNUNET_free (rbuff); |
519 | return bf; | 526 | return bf; |
520 | } | 527 | } |
@@ -535,7 +542,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
535 | */ | 542 | */ |
536 | struct GNUNET_CONTAINER_BloomFilter * | 543 | struct GNUNET_CONTAINER_BloomFilter * |
537 | GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, | 544 | GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, |
538 | unsigned int k) | 545 | unsigned int k) |
539 | { | 546 | { |
540 | struct GNUNET_CONTAINER_BloomFilter *bf; | 547 | struct GNUNET_CONTAINER_BloomFilter *bf; |
541 | size_t ui; | 548 | size_t ui; |
@@ -546,19 +553,19 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, | |||
546 | while (ui < size) | 553 | while (ui < size) |
547 | ui *= 2; | 554 | ui *= 2; |
548 | if (size != ui) | 555 | if (size != ui) |
549 | { | 556 | { |
550 | GNUNET_break (0); | 557 | GNUNET_break (0); |
551 | return NULL; | 558 | return NULL; |
552 | } | 559 | } |
553 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); | 560 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); |
554 | bf->filename = NULL; | 561 | bf->filename = NULL; |
555 | bf->fh = NULL; | 562 | bf->fh = NULL; |
556 | bf->bitArray = GNUNET_malloc_large (size); | 563 | bf->bitArray = GNUNET_malloc_large (size); |
557 | if (bf->bitArray == NULL) | 564 | if (bf->bitArray == NULL) |
558 | { | 565 | { |
559 | GNUNET_free (bf); | 566 | GNUNET_free (bf); |
560 | return NULL; | 567 | return NULL; |
561 | } | 568 | } |
562 | bf->bitArraySize = size; | 569 | bf->bitArraySize = size; |
563 | bf->addressesPerElement = k; | 570 | bf->addressesPerElement = k; |
564 | if (data != NULL) | 571 | if (data != NULL) |
@@ -580,8 +587,8 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, | |||
580 | */ | 587 | */ |
581 | int | 588 | int |
582 | GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct | 589 | GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct |
583 | GNUNET_CONTAINER_BloomFilter *bf, | 590 | GNUNET_CONTAINER_BloomFilter *bf, |
584 | char *data, size_t size) | 591 | char *data, size_t size) |
585 | { | 592 | { |
586 | if (NULL == bf) | 593 | if (NULL == bf) |
587 | return GNUNET_SYSERR; | 594 | return GNUNET_SYSERR; |
@@ -638,7 +645,7 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf) | |||
638 | */ | 645 | */ |
639 | int | 646 | int |
640 | GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter | 647 | GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter |
641 | *bf, const GNUNET_HashCode * e) | 648 | *bf, const GNUNET_HashCode * e) |
642 | { | 649 | { |
643 | int res; | 650 | int res; |
644 | 651 | ||
@@ -658,7 +665,7 @@ GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter | |||
658 | */ | 665 | */ |
659 | void | 666 | void |
660 | GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, | 667 | GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, |
661 | const GNUNET_HashCode * e) | 668 | const GNUNET_HashCode * e) |
662 | { | 669 | { |
663 | if (NULL == bf) | 670 | if (NULL == bf) |
664 | return; | 671 | return; |
@@ -678,7 +685,7 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
678 | */ | 685 | */ |
679 | int | 686 | int |
680 | GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, | 687 | GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, |
681 | const char *data, size_t size) | 688 | const char *data, size_t size) |
682 | { | 689 | { |
683 | unsigned int i; | 690 | unsigned int i; |
684 | unsigned int n; | 691 | unsigned int n; |
@@ -712,8 +719,8 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
712 | */ | 719 | */ |
713 | int | 720 | int |
714 | GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, | 721 | GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, |
715 | const struct GNUNET_CONTAINER_BloomFilter | 722 | const struct GNUNET_CONTAINER_BloomFilter |
716 | *to_or, size_t size) | 723 | *to_or, size_t size) |
717 | { | 724 | { |
718 | unsigned int i; | 725 | unsigned int i; |
719 | unsigned int n; | 726 | unsigned int n; |
@@ -743,7 +750,7 @@ GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
743 | */ | 750 | */ |
744 | void | 751 | void |
745 | GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, | 752 | GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, |
746 | const GNUNET_HashCode * e) | 753 | const GNUNET_HashCode * e) |
747 | { | 754 | { |
748 | if (NULL == bf) | 755 | if (NULL == bf) |
749 | return; | 756 | return; |
@@ -765,9 +772,9 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
765 | */ | 772 | */ |
766 | void | 773 | void |
767 | GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, | 774 | GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, |
768 | GNUNET_HashCodeIterator iterator, | 775 | GNUNET_HashCodeIterator iterator, |
769 | void *iterator_cls, size_t size, | 776 | void *iterator_cls, size_t size, |
770 | unsigned int k) | 777 | unsigned int k) |
771 | { | 778 | { |
772 | GNUNET_HashCode hc; | 779 | GNUNET_HashCode hc; |
773 | unsigned int i; | 780 | unsigned int i; |
@@ -776,7 +783,7 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
776 | i = 1; | 783 | i = 1; |
777 | while (i < size) | 784 | while (i < size) |
778 | i *= 2; | 785 | i *= 2; |
779 | size = i; /* make sure it's a power of 2 */ | 786 | size = i; /* make sure it's a power of 2 */ |
780 | 787 | ||
781 | bf->bitArraySize = size; | 788 | bf->bitArraySize = size; |
782 | bf->bitArray = GNUNET_malloc (size); | 789 | bf->bitArray = GNUNET_malloc (size); |