diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-11-01 20:47:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-11-01 20:47:52 +0000 |
commit | 652e89b59ed2207c2c12172fdabcd6e659995c81 (patch) | |
tree | f054c819d483c1056e18c1099afd4c7fcd2582a0 /src/util/container_bloomfilter.c | |
parent | 5e4113e83368849500792e57946c3d8dd9e548d8 (diff) | |
download | gnunet-652e89b59ed2207c2c12172fdabcd6e659995c81.tar.gz gnunet-652e89b59ed2207c2c12172fdabcd6e659995c81.zip |
fixing bio testcase and a bug in bio.c, also indenting
Diffstat (limited to 'src/util/container_bloomfilter.c')
-rw-r--r-- | src/util/container_bloomfilter.c | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index 1ed09296d..8e44f4fc6 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c | |||
@@ -142,7 +142,8 @@ testBit (char *bitArray, unsigned int bitIdx) | |||
142 | * @param fh A file to keep the 4 bit address usage counters in | 142 | * @param fh A file to keep the 4 bit address usage counters in |
143 | */ | 143 | */ |
144 | static void | 144 | static void |
145 | incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) | 145 | incrementBit (char *bitArray, unsigned int bitIdx, |
146 | const struct GNUNET_DISK_FileHandle *fh) | ||
146 | { | 147 | { |
147 | off_t fileSlot; | 148 | off_t fileSlot; |
148 | unsigned char value; | 149 | unsigned char value; |
@@ -157,8 +158,8 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File | |||
157 | fileSlot = bitIdx / 2; | 158 | fileSlot = bitIdx / 2; |
158 | targetLoc = bitIdx % 2; | 159 | targetLoc = bitIdx % 2; |
159 | 160 | ||
160 | GNUNET_assert (fileSlot == | 161 | GNUNET_assert (fileSlot == |
161 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); | 162 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); |
162 | if (1 != GNUNET_DISK_file_read (fh, &value, 1)) | 163 | if (1 != GNUNET_DISK_file_read (fh, &value, 1)) |
163 | value = 0; | 164 | value = 0; |
164 | low = value & 0xF; | 165 | low = value & 0xF; |
@@ -175,9 +176,9 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File | |||
175 | high++; | 176 | high++; |
176 | } | 177 | } |
177 | value = ((high << 4) | low); | 178 | value = ((high << 4) | low); |
178 | GNUNET_assert (fileSlot == GNUNET_DISK_file_seek (fh, | 179 | GNUNET_assert (fileSlot == GNUNET_DISK_file_seek (fh, |
179 | fileSlot, | 180 | fileSlot, |
180 | GNUNET_DISK_SEEK_SET)); | 181 | GNUNET_DISK_SEEK_SET)); |
181 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); | 182 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); |
182 | } | 183 | } |
183 | 184 | ||
@@ -190,7 +191,8 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File | |||
190 | * @param fh A file to keep the 4bit address usage counters in | 191 | * @param fh A file to keep the 4bit address usage counters in |
191 | */ | 192 | */ |
192 | static void | 193 | static void |
193 | decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) | 194 | decrementBit (char *bitArray, unsigned int bitIdx, |
195 | const struct GNUNET_DISK_FileHandle *fh) | ||
194 | { | 196 | { |
195 | off_t fileSlot; | 197 | off_t fileSlot; |
196 | unsigned char value; | 198 | unsigned char value; |
@@ -243,8 +245,7 @@ decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File | |||
243 | * @return GNUNET_OK if created ok, GNUNET_SYSERR otherwise | 245 | * @return GNUNET_OK if created ok, GNUNET_SYSERR otherwise |
244 | */ | 246 | */ |
245 | static int | 247 | static int |
246 | makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, | 248 | makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size) |
247 | size_t size) | ||
248 | { | 249 | { |
249 | char *buffer; | 250 | char *buffer; |
250 | size_t bytesleft = size; | 251 | size_t bytesleft = size; |
@@ -286,7 +287,7 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, | |||
286 | * @param bit the current bit | 287 | * @param bit the current bit |
287 | */ | 288 | */ |
288 | typedef void (*BitIterator) (void *cls, | 289 | typedef void (*BitIterator) (void *cls, |
289 | struct GNUNET_CONTAINER_BloomFilter * bf, | 290 | struct GNUNET_CONTAINER_BloomFilter * bf, |
290 | unsigned int bit); | 291 | unsigned int bit); |
291 | 292 | ||
292 | /** | 293 | /** |
@@ -314,9 +315,9 @@ iterateBits (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
314 | { | 315 | { |
315 | while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) | 316 | while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) |
316 | { | 317 | { |
317 | callback (arg, | 318 | callback (arg, |
318 | bf, | 319 | bf, |
319 | (((uint32_t *) &tmp[round & 1])[slot]) & | 320 | (((uint32_t *) & tmp[round & 1])[slot]) & |
320 | ((bf->bitArraySize * 8) - 1)); | 321 | ((bf->bitArraySize * 8) - 1)); |
321 | slot++; | 322 | slot++; |
322 | bitCount--; | 323 | bitCount--; |
@@ -342,7 +343,7 @@ iterateBits (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
342 | */ | 343 | */ |
343 | static void | 344 | static void |
344 | incrementBitCallback (void *cls, | 345 | incrementBitCallback (void *cls, |
345 | struct GNUNET_CONTAINER_BloomFilter *bf, | 346 | struct GNUNET_CONTAINER_BloomFilter *bf, |
346 | unsigned int bit) | 347 | unsigned int bit) |
347 | { | 348 | { |
348 | incrementBit (bf->bitArray, bit, bf->fh); | 349 | incrementBit (bf->bitArray, bit, bf->fh); |
@@ -357,7 +358,7 @@ incrementBitCallback (void *cls, | |||
357 | */ | 358 | */ |
358 | static void | 359 | static void |
359 | decrementBitCallback (void *cls, | 360 | decrementBitCallback (void *cls, |
360 | struct GNUNET_CONTAINER_BloomFilter *bf, | 361 | struct GNUNET_CONTAINER_BloomFilter *bf, |
361 | unsigned int bit) | 362 | unsigned int bit) |
362 | { | 363 | { |
363 | decrementBit (bf->bitArray, bit, bf->fh); | 364 | decrementBit (bf->bitArray, bit, bf->fh); |
@@ -372,7 +373,7 @@ decrementBitCallback (void *cls, | |||
372 | */ | 373 | */ |
373 | static void | 374 | static void |
374 | testBitCallback (void *cls, | 375 | testBitCallback (void *cls, |
375 | struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) | 376 | struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) |
376 | { | 377 | { |
377 | int *arg = cls; | 378 | int *arg = cls; |
378 | if (GNUNET_NO == testBit (bf->bitArray, bit)) | 379 | if (GNUNET_NO == testBit (bf->bitArray, bit)) |
@@ -392,9 +393,8 @@ testBitCallback (void *cls, | |||
392 | * @return the bloomfilter | 393 | * @return the bloomfilter |
393 | */ | 394 | */ |
394 | struct GNUNET_CONTAINER_BloomFilter * | 395 | struct GNUNET_CONTAINER_BloomFilter * |
395 | GNUNET_CONTAINER_bloomfilter_load (const char *filename, | 396 | GNUNET_CONTAINER_bloomfilter_load (const char *filename, |
396 | size_t size, | 397 | size_t size, unsigned int k) |
397 | unsigned int k) | ||
398 | { | 398 | { |
399 | struct GNUNET_CONTAINER_BloomFilter *bf; | 399 | struct GNUNET_CONTAINER_BloomFilter *bf; |
400 | char *rbuff; | 400 | char *rbuff; |
@@ -416,8 +416,9 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, | |||
416 | if (filename != NULL) | 416 | if (filename != NULL) |
417 | { | 417 | { |
418 | bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE | 418 | bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE |
419 | | GNUNET_DISK_OPEN_CREATE, | 419 | | GNUNET_DISK_OPEN_CREATE, |
420 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 420 | GNUNET_DISK_PERM_USER_READ | |
421 | GNUNET_DISK_PERM_USER_WRITE); | ||
421 | if (NULL == bf->fh) | 422 | if (NULL == bf->fh) |
422 | { | 423 | { |
423 | GNUNET_free (bf); | 424 | GNUNET_free (bf); |
@@ -446,12 +447,11 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, | |||
446 | int res; | 447 | int res; |
447 | 448 | ||
448 | res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); | 449 | res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); |
449 | if (res == -1) | 450 | if (res == -1) |
450 | { | 451 | { |
451 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 452 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
452 | "read", | 453 | "read", bf->filename); |
453 | bf->filename); | 454 | } |
454 | } | ||
455 | if (res == 0) | 455 | if (res == 0) |
456 | break; /* is ok! we just did not use that many bits yet */ | 456 | break; /* is ok! we just did not use that many bits yet */ |
457 | for (i = 0; i < res; i++) | 457 | for (i = 0; i < res; i++) |
@@ -486,8 +486,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, | |||
486 | */ | 486 | */ |
487 | struct GNUNET_CONTAINER_BloomFilter * | 487 | struct GNUNET_CONTAINER_BloomFilter * |
488 | GNUNET_CONTAINER_bloomfilter_init (const char *data, | 488 | GNUNET_CONTAINER_bloomfilter_init (const char *data, |
489 | size_t size, | 489 | size_t size, unsigned int k) |
490 | unsigned int k) | ||
491 | { | 490 | { |
492 | struct GNUNET_CONTAINER_BloomFilter *bf; | 491 | struct GNUNET_CONTAINER_BloomFilter *bf; |
493 | size_t ui; | 492 | size_t ui; |
@@ -527,8 +526,7 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, | |||
527 | */ | 526 | */ |
528 | int | 527 | int |
529 | GNUNET_CONTAINER_bloomfilter_get_raw_data (struct GNUNET_CONTAINER_BloomFilter | 528 | GNUNET_CONTAINER_bloomfilter_get_raw_data (struct GNUNET_CONTAINER_BloomFilter |
530 | *bf, char *data, | 529 | *bf, char *data, size_t size) |
531 | size_t size) | ||
532 | { | 530 | { |
533 | if (NULL == bf) | 531 | if (NULL == bf) |
534 | return GNUNET_SYSERR; | 532 | return GNUNET_SYSERR; |
@@ -624,8 +622,7 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
624 | */ | 622 | */ |
625 | int | 623 | int |
626 | GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, | 624 | GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, |
627 | const char *data, | 625 | const char *data, size_t size) |
628 | size_t size) | ||
629 | { | 626 | { |
630 | unsigned int i; | 627 | unsigned int i; |
631 | 628 | ||
@@ -671,9 +668,8 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
671 | void | 668 | void |
672 | GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, | 669 | GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, |
673 | GNUNET_HashCodeIterator iterator, | 670 | GNUNET_HashCodeIterator iterator, |
674 | void *iterator_cls, | 671 | void *iterator_cls, |
675 | size_t size, | 672 | size_t size, unsigned int k) |
676 | unsigned int k) | ||
677 | { | 673 | { |
678 | GNUNET_HashCode hc; | 674 | GNUNET_HashCode hc; |
679 | unsigned int i; | 675 | unsigned int i; |