src/hyperloglog

  Source   Edit

Types

HLL = object
  exactMaxBytes: int
  sparseMaxBytes: int
  card: uint64
  encoding: HLLEncoding
  reglen: int
  registers: seq[byte]
HyperLogLog data structure. Allows getting approximate cardinality of large sets in constant time and memory.   Source   Edit

Procs

proc `+`(a, b: HLL): HLL {....raises: [], tags: [].}

Alias for union(a, b)

See also:

  Source   Edit
proc add[A](hll: var HLL; key: A): bool {.discardable.}

Alias for incl.

See also:

  Source   Edit
proc card(hlls: varargs[HLL]): int {....raises: [], tags: [].}

Returns the number of elements in the union of all given hlls. This is equivalent to union(hlls).len, but a little bit more performant.

See also:

  Source   Edit
proc clear(hll: var HLL) {....raises: [], tags: [].}
Removes all elements from hll (without freeing up memory, so it can be reused).   Source   Edit
proc getLen(hll: var HLL): int {....raises: [], tags: [].}

Returns the number of elements in hll. This will use cached cardinality if it's available, otherwise it will be computed and stored (so this call has side effects).

See also:

  Source   Edit
proc hash(hll: HLL): Hash {....raises: [], tags: [].}
Returns hash of hll.   Source   Edit
proc incl[A](hll: var HLL; key: A): bool {.discardable.}
Includes an element key in hll. Returns true if the data structure was modified by this operation.   Source   Edit
proc initHLL(sparseMaxBytes: int = 3000; exactMaxBytes: int = 0): HLL {.
    ...raises: [], tags: [].}
Creates an HLL object. By default, HLL is created using sparse encoding (unless exactMaxBytes is greater than 0). This will be upgraded to the sparse/dense representation as needed. You can pass sparseMaxBytes/exactMaxBytes arguments to specify the actual thresholds.   Source   Edit
func len(hll: HLL): int {....raises: [], tags: [].}

Returns the number of elements in hll. This will use cached cardinality if it's available, but won't update it, so it's side-effect free.

See also:

  Source   Edit
proc merge(hlls: varargs[HLL]): HLL {....raises: [], tags: [].}

Alias for union(hlls)

See also:

  Source   Edit
proc toBytes(hll: HLL): seq[byte] {....raises: [], tags: [].}

Serializes hll to a byte array, so it can be stored and deserialized later.

See also:

  Source   Edit
proc toHLL(bytes: seq[byte]; sparseMaxBytes: int = 3000; exactMaxBytes: int = 0): HLL {.
    ...raises: [], tags: [].}

Restores HyperLogLog from a byte array bytes.

See also:

  Source   Edit
proc union(hlls: varargs[HLL]): HLL {....raises: [], tags: [].}
Returns the union of the HyperLogLogs hlls.   Source   Edit