aboutsummaryrefslogtreecommitdiff
path: root/src/util/container_bloomfilter.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-09-28 21:46:31 +0000
committerChristian Grothoff <christian@grothoff.org>2009-09-28 21:46:31 +0000
commitc2884462a215b5154f7696d7b326f4b0c7c79978 (patch)
tree79bc0b291e4b8392f0df3fc539baa2c236c1865b /src/util/container_bloomfilter.c
parentf382e72693736dc473d9d7ec4815614cdc835b43 (diff)
downloadgnunet-c2884462a215b5154f7696d7b326f4b0c7c79978.tar.gz
gnunet-c2884462a215b5154f7696d7b326f4b0c7c79978.zip
fixing types
Diffstat (limited to 'src/util/container_bloomfilter.c')
-rw-r--r--src/util/container_bloomfilter.c54
1 files changed, 33 insertions, 21 deletions
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c
index 5cc947bd6..39baed6c7 100644
--- a/src/util/container_bloomfilter.c
+++ b/src/util/container_bloomfilter.c
@@ -70,7 +70,7 @@ struct GNUNET_CONTAINER_BloomFilter
70 /** 70 /**
71 * Size of bitArray in bytes 71 * Size of bitArray in bytes
72 */ 72 */
73 unsigned int bitArraySize; 73 size_t bitArraySize;
74 74
75}; 75};
76 76
@@ -85,7 +85,7 @@ struct GNUNET_CONTAINER_BloomFilter
85static void 85static void
86setBit (char *bitArray, unsigned int bitIdx) 86setBit (char *bitArray, unsigned int bitIdx)
87{ 87{
88 unsigned int arraySlot; 88 size_t arraySlot;
89 unsigned int targetBit; 89 unsigned int targetBit;
90 90
91 arraySlot = bitIdx / 8; 91 arraySlot = bitIdx / 8;
@@ -103,7 +103,7 @@ setBit (char *bitArray, unsigned int bitIdx)
103static void 103static void
104clearBit (char *bitArray, unsigned int bitIdx) 104clearBit (char *bitArray, unsigned int bitIdx)
105{ 105{
106 unsigned int slot; 106 size_t slot;
107 unsigned int targetBit; 107 unsigned int targetBit;
108 108
109 slot = bitIdx / 8; 109 slot = bitIdx / 8;
@@ -121,7 +121,7 @@ clearBit (char *bitArray, unsigned int bitIdx)
121static int 121static int
122testBit (char *bitArray, unsigned int bitIdx) 122testBit (char *bitArray, unsigned int bitIdx)
123{ 123{
124 unsigned int slot; 124 size_t slot;
125 unsigned int targetBit; 125 unsigned int targetBit;
126 126
127 slot = bitIdx / 8; 127 slot = bitIdx / 8;
@@ -144,7 +144,7 @@ testBit (char *bitArray, unsigned int bitIdx)
144static void 144static void
145incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) 145incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh)
146{ 146{
147 unsigned int fileSlot; 147 off_t fileSlot;
148 unsigned char value; 148 unsigned char value;
149 unsigned int high; 149 unsigned int high;
150 unsigned int low; 150 unsigned int low;
@@ -157,7 +157,8 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File
157 fileSlot = bitIdx / 2; 157 fileSlot = bitIdx / 2;
158 targetLoc = bitIdx % 2; 158 targetLoc = bitIdx % 2;
159 159
160 GNUNET_assert (fileSlot == (unsigned int) GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); 160 GNUNET_assert (fileSlot ==
161 GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET));
161 if (1 != GNUNET_DISK_file_read (fh, &value, 1)) 162 if (1 != GNUNET_DISK_file_read (fh, &value, 1))
162 value = 0; 163 value = 0;
163 low = value & 0xF; 164 low = value & 0xF;
@@ -174,7 +175,9 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File
174 high++; 175 high++;
175 } 176 }
176 value = ((high << 4) | low); 177 value = ((high << 4) | low);
177 GNUNET_assert (fileSlot == (unsigned int) GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); 178 GNUNET_assert (fileSlot == GNUNET_DISK_file_seek (fh,
179 fileSlot,
180 GNUNET_DISK_SEEK_SET));
178 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); 181 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
179} 182}
180 183
@@ -189,7 +192,7 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File
189static void 192static void
190decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) 193decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh)
191{ 194{
192 unsigned int fileSlot; 195 off_t fileSlot;
193 unsigned char value; 196 unsigned char value;
194 unsigned int high; 197 unsigned int high;
195 unsigned int low; 198 unsigned int low;
@@ -240,10 +243,11 @@ decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File
240 * @return GNUNET_OK if created ok, GNUNET_SYSERR otherwise 243 * @return GNUNET_OK if created ok, GNUNET_SYSERR otherwise
241 */ 244 */
242static int 245static int
243makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, unsigned int size) 246makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh,
247 size_t size)
244{ 248{
245 char *buffer; 249 char *buffer;
246 unsigned int bytesleft = size; 250 size_t bytesleft = size;
247 int res = 0; 251 int res = 0;
248 252
249 if (GNUNET_DISK_handle_invalid (fh)) 253 if (GNUNET_DISK_handle_invalid (fh))
@@ -270,7 +274,7 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, unsigned int size)
270 return GNUNET_OK; 274 return GNUNET_OK;
271} 275}
272 276
273/* ************** GNUNET_CONTAINER_BloomFilter GNUNET_CRYPTO_hash iterator ********* */ 277/* ************** GNUNET_CONTAINER_BloomFilter iterator ********* */
274 278
275/** 279/**
276 * Iterator (callback) method to be called by the 280 * Iterator (callback) method to be called by the
@@ -308,11 +312,11 @@ iterateBits (struct GNUNET_CONTAINER_BloomFilter *bf,
308 round = 0; 312 round = 0;
309 while (bitCount > 0) 313 while (bitCount > 0)
310 { 314 {
311 while (slot < (sizeof (GNUNET_HashCode) / sizeof (unsigned int))) 315 while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t)))
312 { 316 {
313 callback (arg, 317 callback (arg,
314 bf, 318 bf,
315 (((unsigned int *) &tmp[round & 1])[slot]) & 319 (((uint32_t *) &tmp[round & 1])[slot]) &
316 ((bf->bitArraySize * 8) - 1)); 320 ((bf->bitArraySize * 8) - 1));
317 slot++; 321 slot++;
318 bitCount--; 322 bitCount--;
@@ -388,14 +392,15 @@ testBitCallback (void *cls,
388 * @return the bloomfilter 392 * @return the bloomfilter
389 */ 393 */
390struct GNUNET_CONTAINER_BloomFilter * 394struct GNUNET_CONTAINER_BloomFilter *
391GNUNET_CONTAINER_bloomfilter_load (const char *filename, unsigned int size, 395GNUNET_CONTAINER_bloomfilter_load (const char *filename,
396 size_t size,
392 unsigned int k) 397 unsigned int k)
393{ 398{
394 struct GNUNET_CONTAINER_BloomFilter *bf; 399 struct GNUNET_CONTAINER_BloomFilter *bf;
395 char *rbuff; 400 char *rbuff;
396 unsigned int pos; 401 off_t pos;
397 int i; 402 int i;
398 unsigned int ui; 403 size_t ui;
399 404
400 if ((k == 0) || (size == 0)) 405 if ((k == 0) || (size == 0))
401 return NULL; 406 return NULL;
@@ -480,11 +485,12 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, unsigned int size,
480 * @return the bloomfilter 485 * @return the bloomfilter
481 */ 486 */
482struct GNUNET_CONTAINER_BloomFilter * 487struct GNUNET_CONTAINER_BloomFilter *
483GNUNET_CONTAINER_bloomfilter_init (const char *data, unsigned int size, 488GNUNET_CONTAINER_bloomfilter_init (const char *data,
489 size_t size,
484 unsigned int k) 490 unsigned int k)
485{ 491{
486 struct GNUNET_CONTAINER_BloomFilter *bf; 492 struct GNUNET_CONTAINER_BloomFilter *bf;
487 unsigned int ui; 493 size_t ui;
488 494
489 if ((k == 0) || (size == 0)) 495 if ((k == 0) || (size == 0))
490 return NULL; 496 return NULL;
@@ -520,7 +526,8 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, unsigned int size,
520 */ 526 */
521int 527int
522GNUNET_CONTAINER_bloomfilter_get_raw_data (struct GNUNET_CONTAINER_BloomFilter 528GNUNET_CONTAINER_bloomfilter_get_raw_data (struct GNUNET_CONTAINER_BloomFilter
523 *bf, char *data, unsigned int size) 529 *bf, char *data,
530 size_t size)
524{ 531{
525 if (NULL == bf) 532 if (NULL == bf)
526 return GNUNET_SYSERR; 533 return GNUNET_SYSERR;
@@ -611,11 +618,15 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
611 * data of the given bloom filter. Assumes that 618 * data of the given bloom filter. Assumes that
612 * the size of the data array and the current filter 619 * the size of the data array and the current filter
613 * match. 620 * match.
621 *
614 * @param bf the filter 622 * @param bf the filter
623 * @param data the data to or-in
624 * @param size number of bytes in data
615 */ 625 */
616int 626int
617GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, 627GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
618 const char *data, unsigned int size) 628 const char *data,
629 size_t size)
619{ 630{
620 unsigned int i; 631 unsigned int i;
621 632
@@ -661,7 +672,8 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
661void 672void
662GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, 673GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
663 GNUNET_HashCodeIterator iterator, 674 GNUNET_HashCodeIterator iterator,
664 void *iterator_arg, unsigned int size, 675 void *iterator_arg,
676 size_t size,
665 unsigned int k) 677 unsigned int k)
666{ 678{
667 GNUNET_HashCode hc; 679 GNUNET_HashCode hc;