Add a third default.
[oweals/gnunet.git] / src / util / container_bloomfilter.c
index d6c2cb8b9cddf385d6485c0c67fdcabb7be1186b..579c1261db5b2a36af741d43ae9a1000def785d7 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -40,9 +40,7 @@
  */
 
 #include "platform.h"
-#include "gnunet_common.h"
-#include "gnunet_container_lib.h"
-#include "gnunet_disk_lib.h"
+#include "gnunet_util_lib.h"
 
 #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
 
@@ -183,7 +181,7 @@ static void
 incrementBit (char *bitArray, unsigned int bitIdx,
               const struct GNUNET_DISK_FileHandle *fh)
 {
-  OFF_T fileSlot;
+  off_t fileSlot;
   unsigned char value;
   unsigned int high;
   unsigned int low;
@@ -231,7 +229,7 @@ static void
 decrementBit (char *bitArray, unsigned int bitIdx,
               const struct GNUNET_DISK_FileHandle *fh)
 {
-  OFF_T fileslot;
+  off_t fileslot;
   unsigned char value;
   unsigned int high;
   unsigned int low;
@@ -464,10 +462,10 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
 {
   struct GNUNET_CONTAINER_BloomFilter *bf;
   char *rbuff;
-  OFF_T pos;
+  off_t pos;
   int i;
   size_t ui;
-  OFF_T fsize;
+  off_t fsize;
   int must_read;
 
   GNUNET_assert (NULL != filename);
@@ -560,8 +558,8 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
   }
   bf->bitArraySize = size;
   bf->addressesPerElement = k;
-  if (GNUNET_YES != must_read)      
-    return bf; /* already done! */  
+  if (GNUNET_YES != must_read)
+    return bf; /* already done! */
   /* Read from the file what bits we can */
   rbuff = GNUNET_malloc (BUFFSIZE);
   pos = 0;
@@ -774,22 +772,27 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
  *
  * @param bf the filter
  * @param to_or the bloomfilter to or-in
- * @param size number of bytes in data
+ * @return #GNUNET_OK on success
  */
 int
 GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
                                   const struct GNUNET_CONTAINER_BloomFilter
-                                  *to_or, size_t size)
+                                  *to_or)
 {
   unsigned int i;
   unsigned int n;
   unsigned long long *fc;
   const unsigned long long *dc;
+  size_t size;
 
   if (NULL == bf)
-    return GNUNET_YES;
-  if (bf->bitArraySize != size)
+    return GNUNET_OK;
+  if (bf->bitArraySize != to_or->bitArraySize)
+  {
+    GNUNET_break (0);
     return GNUNET_SYSERR;
+  }
+  size = bf->bitArraySize;
   fc = (unsigned long long *) bf->bitArray;
   dc = (const unsigned long long *) to_or->bitArray;
   n = size / sizeof (unsigned long long);
@@ -801,6 +804,7 @@ GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
   return GNUNET_OK;
 }
 
+
 /**
  * Remove an element from the filter.
  *