Algori...LogLog(3pm)
π Algorithm::HyperLogLog β the manual, but make it cute π
okay so bestie, you found the docs for Algorithm::HyperLogLog, which lives in section 3pm of the manual (that's the Perl modules section, iykyk). It's an implementation of the HyperLogLog cardinality estimation algorithm. Yes that's a mouthful, no you don't have to say it out loud. Sit down, grab a strawberry π, and let's go.
β¨ NAME β¨
Algorithm::HyperLogLog β an implementation of the HyperLogLog cardinality estimation algorithm. It counts how many distinct things you've seen without actually remembering any of them. Iconic behaviour honestly. π
π SYNOPSIS π
The basic vibe, feed it stuff and ask how much stuff there was:
use Algorithm::HyperLogLog;
my $hll = Algorithm::HyperLogLog->new(14);
while(<>){
$hll->add($_);
}
my $cardinality = $hll->estimate(); # Estimate cardinality
$hll->dump_to_file('hll_register.dump');# Dumps internal data
And if you wanna construct an object from a dumped file, like reconnecting with your past self:
use Algorithm::HyperLogLog;
# Restore internal state
my $hll = Algorithm::HyperLogLog->new_from_file('hll_register.dump');
π¦ DESCRIPTION π¦
This module is an implementation of the HyperLogLog algorithm.
HyperLogLog is an algorithm for estimating the cardinality of a set. That's the whole thing. That's the plot. β¨
π METHODS π
πΈ new($b)
The constructor. Birth. Main character origin story.
$b is the parameter that determines register size. And the register size is 2^$b, so yes, $b is doing the heavy lifting here.
$b must be an integer between 4 and 16. Not 3. Not 17. Bestie, we have boundaries. π§
πΈ new_from_file($filename)
This method constructs an object AND restores the internal data of that object from a dumped file (the kind of file you get from dump_to_file()). It's giving "resurrection but make it serialization". π§
πΈ dump_to_file($filename)
This method dumps the internal data of an object to a file. Saving your progress, girlypop style. πΎ
πΈ add($data)
Adds an element to the cardinality estimator. One little data crumb at a time. π
πΈ estimate()
Returns the estimated cardinality value in floating point number. So like, a real number, not a cute little integer. Adjust expectations accordingly. π
πΈ merge($other)
Merges the estimate from 'other' into this object, and returns the estimate of their union. Friendship! Union! Mathematical slay! π«Ά
πΈ register_size()
Returns the number of registers. Small but important caveat: in the XS implementation, this equals the size in bytes. So don't be surprised, it's the same number there. π
πΈ XS()
If you're using the XS backend, this method returns a true value. That's it. That's the method. A little yes/no vibe check. β
π SEE ALSO π
Philippe Flajolet, Γric Fusy, Olivier Gandouet and FrΓ©dΓ©ric Meunier. HyperLogLog: the analysis of a near-optimal cardinality estimation algorithm. 2007 Conference on Analysis of Algorithms, DMTCS proc. AH, pp. 127β146, 2007.
<http://algo.inria.fr/flajolet/Publications/FlFuGaMe07.pdf>
The source material. The lore. Read it if you're feeling academic. π₯
π AUTHOR π
Hideaki Ohno <hide.o.j55 {at} gmail.com>
π THANKS TO π
MurmurHash3 (<https://github.com/PeterScott/murmur3>)
- Austin Appleby
- Peter Scott
π LICENSE π
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. So like, go off, just keep the same energy. π
ngl bestie, if you got this far you're basically a cardinality girlie now. No cap. π
okay that's the whole page! this was perl v5.42.3, dated 2026-08-19, from the Algori...LogLog(3pm) era of the manual. mwah, go estimate something πβ¨
π¦ where this page comes from
- ubuntu stonking: libalgorithm-hyperloglog-perl 0.24-2build5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms