Algorit...mFilter(3)

πŸ“¦
version 0.02 Β· 2 versions
, in fedora 43

✨ NAME ✨

Algorithm::BloomFilter β€” it's giving A simple bloom filter data structure πŸ’– (and yes bestie, that's the whole name, we keep it exactly like that)


🌸 SYNOPSIS 🌸

okay so here's the vibe, literally copy-paste this energy:

use Algorithm::BloomFilter;

my $filter = Algorithm::BloomFilter->new($absolute_nbits, $n_hashes);

$filter->add("foo", "bar", "baz");
if ($filter->test("bar")) {
  print "Eureka! 'bar' is in!\n";
}

see how cute that is? you build it, you add stuff, you test stuff, you print a little celebration. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

This module implements a simple bloom filter in C/XS. no cap β€” that's it, that's the whole thing. C and XS doing the heavy lifting so you don't have to. πŸ’…


πŸ‘‘ METHODS πŸ‘‘

new

Constructor, bestie. It takes two arguments:

  1. The absolute number of bits to use for the bloom filter storage β€” and heads up, this will be rounded up to the nearest power of 2 πŸ”₯
  2. The number of hash functions to evaluate for each entry.

Algorithm::BloomFilter uses SipHash internally. The C part can also use other hash functions, but the XS wrapper currently only supports SipHash. so like, that's the one you get. periodt. πŸ’œ

add

Given a list of values (that will be converted to byte strings), add those values to the bloom filter. that's it, that's the job, she's adding ✨

test

Given a value (which will be converted to a byte string for this operation), test whether that value is part of the set represented by the bloom filter. vibe check on your data, fr fr πŸ”

merge

Given another bloom filter of exactly the same configuration (same hash function, same number of hash function variants, same number of bits), computes a union of the two filters and stores the result in the invocant bloom filter. two filters become one, it's giving fusion, it's giving main character energy 🫢

serialize

Serializes the bloom filter into a string and returns it. she's going on a little trip, in string form 🧳

deserialize

Class method. Given a previously serialized bloom filter as a string, reconstructs the bloom filter. Returns the newly created Algorithm::BloomFilter object. welcome back queen πŸ‘‘

⚠️ Beware that serialize/deserialize haven't been tested across systems with differing endianess, etc. Please do your own testing (and possibly submit patches to this caveat). not me telling you to go test it yourself 😭 but yeah, do your own testing and maybe send patches, that would slay πŸ’€

πŸ’€ CAVEATS πŸ’€

  • Requires a uint64_t type.
  • Untested on endianness other than x86_64's (little endian).

so like… little endian girlies only rn. 🌈


🌟 SEE ALSO 🌟

Wikipedia: <http://en.wikipedia.org/wiki/Bloom_filter> β€” go read up, iykyk πŸ“š


πŸ’– AUTHOR πŸ’–

Steffen Mueller, <smueller@cpan.org>


Copyright (C) 2014-2015 by Steffen Mueller

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available.


okay and one lil sign-off from me to you: this page came to you via perl v5.42.0, dated 2025-07-25, and it lives in the User Contributed Perl Documentation corner of the manual. now go forth and bloom filter, bestie πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from