Rename bloom_init() to bloom_new().
authorAndre Noll <maan@systemlinux.org>
Wed, 24 Dec 2008 12:59:14 +0000 (13:59 +0100)
committerAndre Noll <maan@systemlinux.org>
Wed, 24 Dec 2008 12:59:14 +0000 (13:59 +0100)
bloom.c
bloom.h
create.c

diff --git a/bloom.c b/bloom.c
index 9b66b903be5d189704d0fedbac0cb07c70bd5113..2aff535e833f75ba178bfcbf0524e0bf19d0cca7 100644 (file)
--- a/bloom.c
+++ b/bloom.c
@@ -12,6 +12,9 @@
 void *adu_calloc(size_t size)
 {
        void *ret = malloc(size);
+
+       if (!ret)
+               exit(EXIT_FAILURE);
        memset(ret, 0, size);
        return ret;
 }
@@ -128,13 +131,15 @@ void bloom_free(struct bloom *b)
 }
 
 /**
- * Initialize a bloom filter.
+ * Allocate and initialize a new bloom filter.
  *
  * \param order Use a filter containing 2^order bits.
  * \param num_hash_functions Set that many bits in the filter per entry.
+ *
+ * \return This function either returns a freshly allocated and initialized
+ * bloom filter or does not return at all (if the underlying malloc() failed).
  */
-int bloom_init(unsigned order, unsigned num_hash_functions,
-               struct bloom **result)
+struct bloom *bloom_new(unsigned order, unsigned num_hash_functions)
 {
        struct bloom *b = adu_calloc(sizeof(*b));
 
@@ -143,8 +148,7 @@ int bloom_init(unsigned order, unsigned num_hash_functions,
        b->order = order;
        b->num_hash_functions = num_hash_functions;
        b->filter = adu_calloc(filter_bits(b) / 8);
-       *result = b;
-       return 1;
+       return b;
 }
 
 #ifdef TEST_BLOOM
@@ -184,7 +188,7 @@ int main(int argc, char **argv)
                printf("k: # of hash functions to use\n");
                exit(1);
        }
-       bloom_init(atoi(argv[1]), atoi(argv[2]), &b);
+       b = bloom_new(atoi(argv[1]), atoi(argv[2]));
        add_stdin(b);
        INFO_LOG("%u%% of bits are set\n", (unsigned)
                (b->num_set_bits * 100ULL / filter_bits(b)));
diff --git a/bloom.h b/bloom.h
index e7f3cd33dc2018d03f410064731c0a8be97b6e59..5121606a404cb1e5bf69c585b1f933216e3e33b3 100644 (file)
--- a/bloom.h
+++ b/bloom.h
@@ -20,7 +20,6 @@ struct bloom {
        uint8_t *filter;
 };
 
-int bloom_init(unsigned bloom_filter_order, unsigned num_hash_functions,
-               struct bloom **result);
+struct bloom *bloom_new(unsigned order, unsigned num_hash_functions);
 void bloom_free(struct bloom *b);
 int bloom_test_and_insert(const uint8_t *data, size_t len, struct bloom *b);
index 51583a65fe4910ab4d5d812d48e26d25745f9cd4..e3f09d4b61726fdac46edef85c458b157ef6431a 100644 (file)
--- a/create.c
+++ b/create.c
@@ -258,8 +258,8 @@ int com_create(void)
        if (!S_ISDIR(statbuf.st_mode))
                return -ERRNO_TO_ERROR(ENOTDIR);
        if (order >= 10 && num > 0) {
-               bloom_init(order, num, &global_bloom_filter);
-               bloom_init(order, num, &user_bloom_filter);
+               global_bloom_filter = bloom_new(order, num);
+               user_bloom_filter = bloom_new(order, num);
        } else
                WARNING_LOG("hard link detection deactivated\n");
        device_id = statbuf.st_dev;