package grenier

  1. Overview
  2. Docs
A collection of various algorithms in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

grenier-0.14.tbz
sha256=e5362e6ad0e888526517415e78b9e8243bb0cc1b0c952201884148832ac4442f
sha512=4e2f16b52b3c2786a1b8e93156184fd69d448cea571ca839b6cb88ab73f380994d1561fe24c1523c43ed8fc42d2ac01b673a13b6151fff4af4f009923d3aaf37

doc/grenier.hll/Hll/index.html

Module Hll

An implementation of HyperLogLog probabilistic cardinality estimator.

type t

Type of HyperLogLog counters

val make : error:float -> t

Create a new counter with error error rate. error should verify 0.0 < error && error < 1.0. 0.05 is a reasonable default.

Use estimate_memory to measure memory consumption and runtime of this function.

val add : t -> int64 -> unit

add t k counts item k in t.

k should be "random": it should be the output of some cryptographic hashing algorithm like SHA. It is not treated as an integer. This is key to getting proper results. No patterns should appear in the bits of the different items added.

Runtime is O(1).

val estimate_memory : error:float -> int

Estimate the memory consumed in bytes by a counter with the specified error rate.

This ignores the constant overhead of the OCaml representation, around two words. It is a bytes of estimate_memory ~error + 1 length.

val card : t -> float

Get the cardinality estimation. Defaults to HyperLogLog++.

val card_hll : t -> float
val card_hllpp : t -> float
val copy : t -> t

Get a copy of a counter.

val merge : into:t -> t -> unit

merge ~into:t0 t' has the same effect as adding all items added to t' to t0.

t0 and t' must have been constructed with the same error rate!

val clear : t -> unit

Reset counter to 0.

val hash_int64 : int64 -> int64

The following algorithm provide a reasonable hashing function for integers, if you want to feed the HLL with "normal" integers.

Serialization

val to_string : t -> string

Returns a string with the current state stored.

val of_string : string -> t

Restore a HLL saved with to_string.

of_string (to_string t) is functionnally equivalent to copy t, except a bit more expensive.

It can raise Invalid_argument if the string provided was not saved by to_string.

OCaml

Innovation. Community. Security.

On This Page
  1. Serialization