Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alindeman/hyperll
HyperLogLog implementation for Ruby (as a C extension)
https://github.com/alindeman/hyperll
Last synced: 2 months ago
JSON representation
HyperLogLog implementation for Ruby (as a C extension)
- Host: GitHub
- URL: https://github.com/alindeman/hyperll
- Owner: alindeman
- License: mit
- Created: 2013-10-23T22:56:16.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-11-06T15:38:07.000Z (about 1 year ago)
- Last Synced: 2024-04-23T06:26:14.363Z (8 months ago)
- Language: C
- Homepage:
- Size: 1.21 MB
- Stars: 22
- Watchers: 3
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Hyperll [![Build Status](https://secure.travis-ci.org/alindeman/hyperll.png?branch=master)](http://travis-ci.org/alindeman/hyperll) [![Coverage Status](https://coveralls.io/repos/alindeman/hyperll/badge.png)](https://coveralls.io/r/alindeman/hyperll)
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.```ruby
hll = Hyperll::HyperLogLog.new(10)
hll.offer(1)
hll.offer(2)
hll.offer(3)
hll.cardinality # => 3hll2 = Hyperll::HyperLogLog.new(10)
hll2.offer(3)
hll2.offer(4)
hll2.offer(5)
hll.cardinality # => 3merged = 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](https://github.com/addthis/stream-lib)
library.```ruby
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
```