Bloom::Filter(3pm)
π Bloom::Filter π
okay bestie, so this is Bloom::Filter, a page from section 3pm of the User Contributed Perl Documentation (yep, the perl crew's own little corner of the manual), and it's a whole sample Perl Bloom filter implementation. no cap, it's adorable and also genuinely useful.
β¨ NAME β¨
Bloom::Filter β a sample Perl Bloom filter implementation. that's the whole name section, short king energy π
πΈ DESCRIPTION πΈ
okay so picture this: a Bloom filter is a probabilistic algorithm for doing existence tests in less memory than a full list of keys would require. the tradeoff?? a certain configurable risk of false positives π«£ like yes she's cheap but sometimes she lies about knowing someone.
this module implements a simple Bloom filter with configurable capacity and false positive rate. Bloom filters were first described in a 1970 paper by Burton Bloom, see <http://portal.acm.org/citation.cfm?id=362692&dl=ACM&coll=portal>. 1970?? and still eating. iconic.
π¦ SYNOPSIS π¦
the vibe, verbatim:
use Bloom::Filter
my $bf = Bloom::Filter->new( capacity => 10, error_rate => .001 );
$bf->add( @keys );
while ( <> ) {
chomp;
print "Found $_\n" if $bf->check( $_ );
}
like look at her go π₯Ή construct, add, check. that's it. that's the whole personality.
π CONSTRUCTORS π
new %PARAMS
creates a brand new instance, fresh out the box, main character energy. the allowable params are error_rate and capacity. that's it bestie, those are the two knobs.
init
calculates the best number of hash functions and optimum filter length, creates some random salts, and generates a blank bit vector. also, it's called automatically by the constructor β so like, she shows up to the party without you even texting her π no need to call it yourself.
π ACCESSORS π
these are the little getter besties, they just report the tea:
capacityβ returns the total capacity of the Bloom filtererror_rateβ returns the configured maximum error ratelengthβ returns the length of the Bloom filter in bitskey_countβ returns the number of items currently stored in the filteron_bitsβ returns the number of 'on' bits in the filtersaltsβ returns the list of salts used to create the hash functions
β PUBLIC METHODS β
add @KEYS
adds the list of keys to the filter. > heads up bestie: she will fail, return undef and complain if the number of keys in the filter exceeds the configured capacity. so don't overstuff her, she will literally text the group chat about it π
check @KEYS
checks the provided key list against the Bloom filter, and returns a list of equivalent length, with true or false values depending on whether there was a match. so like, one answer per key, in order. cute, consistent, no chaos. π
π§ INTERNAL METHODS π§
iykyk, these are the behind-the-scenes girlies. you probably don't touch them, but here they are anyway because we keep every detail in this house π«Ά
_calculate_shortest_filter_length CAPACITY ERR_RATE
given a desired error rate and maximum capacity, returns the optimum combination of vector length (in bits) and number of hash functions to use in building the filter, where "optimum" means shortest vector length. she's giving efficiency queen. periodt.
_get_cells KEY
given a key, hashes it using the list of salts and returns an array of cell indexes corresponding to the key. little salt sprinkle, then boom, cell coordinates β¨
π AUTHOR π
originally written by Maciej Ceglowski <maciej@ceglowski.com>. currently maintained by Grzegorz RoΕΌniecki <xaerxess@gmail.com>. legends, honestly.
π CONTRIBUTORS π
Dmitriy Ryaboy <dmitriy.ryaboy@ask.com> β big speedup in February 2007, thanks! big speedup?? in 2007?? we love a glow-up π
π COPYRIGHT AND LICENSE π
(c) 2004 Maciej Ceglowski
this is free software, distributed under version 2 of the GNU Public License (GPL). free as in go wild, bestie π¦
and that's the whole page, no notes π
this little manual page is from the perl v5.40.1 era, dated 2025-08-15 β so like, she's fresh, she's documented, she's Bloom::Filter(3pm) and she ATE. mwah π
π¦ where this page comes from
- ubuntu resolute: libbloom-filter-perl 1.2-6 Β· GPL-2.0-only
- ubuntu stonking: libbloom-filter-perl 1.2-6 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms