Sorry if this is a bit negative but from a cursory look I wouldn't use this.<p>An efficient Bloom Filter should only allocate on heap exactly once: when allocating the initial bitmap. This implementation seems to be not very efficient as it allocates even during a simple query.<p>The usage of `static` variables makes the BloomFilter code unnecessarily dangerous to use when multiple threads are used even if every thread just wants to allocate and use totally separate bloom filters. Actually it could even cause issues with two bloom filters created after each other since even `Initialize` just returns a pointer to a single static `BloomFilter` :o I can't come up with a reason why you'd consider making anything in there `static`.<p>There is also strange code like this loop <a href="https://github.com/hashlookup/fleur/blob/4ee2644a850381d928ad86fce8b2357f21102eee/fleurcli/fleurcli.c#L102" rel="nofollow">https://github.com/hashlookup/fleur/blob/4ee2644a850381d928a...</a> that jumped into my eye.<p>Oh and btw I believe bloom_path can cause memory safety issues because it is not terminated with a null after strncopy.<p>I would additionally suggest to use some code formatting tool as it's a bit all over the place. But the variable/function names mix various styles as well.
If you want a networked version (note: not based on Fleur): <a href="https://github.com/armon/bloomd" rel="nofollow">https://github.com/armon/bloomd</a> In the source there is a "libbloom" as well that you could copy directly into your codebase if you wanted an embedded version. The networked version has a simple Redis-like text protocol so you can just use `telnet` to play around with it, too.<p>Also written in C, with great performance (no comparison to this one, I haven't done it), and has been used in production by many companies for many years (since ~2012 or 2013).<p>Just pointing out other implementations if anyone is curious!
I appreciate the Go-style docstring comments in the code!<p>For anyone trying to understand Bloom filters who may be interested in checking out an alternative C implementation (designed to be compiled to WebAssembly), I'll link mine below.<p>I used it to build a Bloom filter of every Hacker News submission ever for a privacy-preserving browser extension that tells you if the page you're currently on has been submitted before.<p><a href="https://github.com/jstrieb/hackernews-button/blob/master/bloom-filter/bloom.c" rel="nofollow">https://github.com/jstrieb/hackernews-button/blob/master/blo...</a>
Could be faster still if it didn't calloc/free a "Fingerprint" buffer each time you add or query an entry. Since its individual BloomFilters are not thread-safe anyway, it could allocate the buffer once at BloomFilter creation time and be done with it.
Sorry to be pedant, but using good prefix, or even suffix for C library is a must, and come up with something unique (and "fleur" is kind of cool), probably good idea to prefix with it, and then it can be used without any current or future symbol clashes.