# `Aerospike.Op.HLL`
[🔗](https://github.com/luisgabrielroldan/aerospike_driver/blob/v0.3.1/lib/aerospike/op/hll.ex#L1)

HyperLogLog operations for `Aerospike.operate/4`.

HyperLogLog bins require Aerospike server 4.9 or later. The server does not
support HyperLogLog bins nested inside lists or maps, so these operations do
not accept `ctx:`.

`init/4` and `add/5` default both bit counts to `-1`, which asks the server
to choose its defaults. When set explicitly, index bits are typically 4 to
16, min-hash bits 4 to 58, and their sum must not exceed 64.

Multi-HLL read operations accept `hlls` as a list of `{:bytes, blob}` HLL
values. Modify operations accept mnemonic `flags:` values for the server
write policy.

# `flags`

```elixir
@type flags() :: atom() | [atom()] | non_neg_integer() | {:raw, non_neg_integer()}
```

HyperLogLog write flags.

Accepts `:default`, `:create_only`, `:update_only`, `:no_fail`,
`:allow_fold`, or a list of those atoms. Compatibility callers may pass a
non-negative integer; use `{:raw, integer}` when deliberately sending an
unnamed server value.

# `read_opts`

```elixir
@type read_opts() :: []
```

Options accepted by multi-HLL read helpers.

No option keys are currently encoded for these read operations; the argument
is accepted for API consistency.

# `t`

```elixir
@opaque t()
```

Opaque HyperLogLog operation for `Aerospike.operate/4`.

# `write_opts`

```elixir
@type write_opts() :: [{:flags, flags()}]
```

Options accepted by HyperLogLog modify operations.

Supported key:

* `:flags` - HyperLogLog write flags. Defaults to `:default`.

# `add`

```elixir
@spec add(String.t(), list(), integer(), integer(), write_opts()) :: t()
```

Adds elements to a HyperLogLog bin.

Elements may be strings or `{:bytes, binary}` values. If the bin is missing,
the server creates it using the supplied bit counts.

# `describe`

```elixir
@spec describe(String.t()) :: t()
```

Returns `[index_bit_count, min_hash_bit_count]` for the HyperLogLog bin.

# `fold`

```elixir
@spec fold(String.t(), integer()) :: t()
```

Folds the HyperLogLog bin to a smaller index bit count.

# `get_count`

```elixir
@spec get_count(String.t()) :: t()
```

Returns the estimated cardinality of the HyperLogLog bin.

# `get_intersect_count`

```elixir
@spec get_intersect_count(String.t(), list(), read_opts()) :: t()
```

Returns the estimated cardinality of the intersection of the bin and `hlls`.

# `get_similarity`

```elixir
@spec get_similarity(String.t(), list(), read_opts()) :: t()
```

Returns an estimated similarity score for the bin and `hlls`.

# `get_union`

```elixir
@spec get_union(String.t(), list(), read_opts()) :: t()
```

Returns a HyperLogLog blob containing the union of the bin and `hlls`.

# `get_union_count`

```elixir
@spec get_union_count(String.t(), list(), read_opts()) :: t()
```

Returns the estimated cardinality of the union of the bin and `hlls`.

# `init`

```elixir
@spec init(String.t(), integer(), integer(), write_opts()) :: t()
```

Creates a new HyperLogLog bin or resets an existing one.

# `refresh_count`

```elixir
@spec refresh_count(String.t()) :: t()
```

Refreshes stale cached cardinality and returns the estimated count.

# `set_union`

```elixir
@spec set_union(String.t(), list(), write_opts()) :: t()
```

Merges every HyperLogLog value in `hlls` into the bin.

# `write_allow_fold`

```elixir
@spec write_allow_fold() :: 8
```

Allow folding to less precise HyperLogLog settings when needed.

# `write_create_only`

```elixir
@spec write_create_only() :: 1
```

Only create the HyperLogLog bin when it does not already exist.

# `write_default`

```elixir
@spec write_default() :: 0
```

Use default HyperLogLog write behavior.

# `write_no_fail`

```elixir
@spec write_no_fail() :: 4
```

Do not fail the command when a HyperLogLog operation is denied by write flags.

# `write_update_only`

```elixir
@spec write_update_only() :: 2
```

Only update the HyperLogLog bin when it already exists.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
