Project

hyperll

0.01
No release in over 3 years
Low commit activity in last 3 years
HyperLogLog implementation in pure Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
~> 2.14
 Project Readme

Hyperll Build Status Coverage Status

HyperLogLog implementation for Ruby. Originally written in pure Ruby, many pieces were rewritten in C for increased performance.

Usage

HyperLogLog stores an estimation of the cardinality of a set. It can be merged with other HyperLogLog instances.

hll = Hyperll::HyperLogLog.new(10)
hll.offer(1)
hll.offer(2)
hll.offer(3)
hll.cardinality # => 3

hll2 = Hyperll::HyperLogLog.new(10)
hll2.offer(3)
hll2.offer(4)
hll2.offer(5)
hll.cardinality # => 3

merged = Hyperll::HyperLogLog.new(10)
merged.merge(hll, hll2)
merged.cardinality # => 5

Serialization

HyperLogLog can be serialized to a binary string. It is compatible with the binary format from the Java stream-lib library.

hll = Hyperll::HyperLogLog.new(4)
hll.offer(1)
hll.offer(2)
hll.offer(3)
hll.serialize # => "\x00\x00\x00\x04\x00\x00\x00\f\x02\x00\x00\x00\x00\x00\x88\x00\x00\x00\x00\x00"

hll2 = Hyperll::HyperLogLog.unserialize("\x00\x00\x00\x04\x00\x00\x00\f\x02\x00\x00\x00\x00\x00\x88\x00\x00\x00\x00\x00")
hll2.cardinality # => 3