Algori...LogLog(3pm)

πŸ“¦
version 0.24 Β· 5 versions
, in ubuntu stonking

πŸ’– 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