# Fingerprints

> StringZilla's fingerprints from C++

`#include <stringzilla/ngrams.hpp>` 6.0.0-rc.1 · cb8d956a

## API

### Class `ngrams_engine_t`

Queries filed at one or more N-gram widths, overlapped with any number of candidate batches, and sketching any batch of texts at those widths.8

[ngrams.hpp:30 ↗](https://github.com/ashvardanian/StringZilla/blob/cb8d956a24817c2fd65ead3b0ce22a892eeb9827/cpp/stringzilla/ngrams.hpp#L30)

```cpp
class ngrams_engine_t
```

**See also.**

[sz_ngrams_engine_init](https://www.unum.cloud/docs/stringzilla/c/fingerprints.md#sz_ngrams_engine_init), [sz_ngrams_overlaps](https://www.unum.cloud/docs/stringzilla/c/searching-and-counting.md#sz_ngrams_overlaps), [sz_ngrams_sketches](https://www.unum.cloud/docs/stringzilla/c/fingerprints.md#sz_ngrams_sketches)

#### See also

[sz_ngrams_engine_init](https://www.unum.cloud/docs/stringzilla/c/fingerprints.md#sz_ngrams_engine_init), [sz_ngrams_overlaps](https://www.unum.cloud/docs/stringzilla/c/searching-and-counting.md#sz_ngrams_overlaps), [sz_ngrams_sketches](https://www.unum.cloud/docs/stringzilla/c/fingerprints.md#sz_ngrams_sketches)

##### `ngrams_engine_t`

Holds nothing, so every verb refuses.

[ngrams.hpp:35 ↗](https://github.com/ashvardanian/StringZilla/blob/cb8d956a24817c2fd65ead3b0ce22a892eeb9827/cpp/stringzilla/ngrams.hpp#L35)

```cpp
ngrams_engine_t() noexcept=default;
```

```cpp
ngrams_engine_t(ngrams_engine_t && other) noexcept;
```

##### `operator=`

[ngrams.hpp:37 ↗](https://github.com/ashvardanian/StringZilla/blob/cb8d956a24817c2fd65ead3b0ce22a892eeb9827/cpp/stringzilla/ngrams.hpp#L37)

```cpp
ngrams_engine_t & operator=(ngrams_engine_t && other) noexcept;
```

##### `~ngrams_engine_t`

[ngrams.hpp:41 ↗](https://github.com/ashvardanian/StringZilla/blob/cb8d956a24817c2fd65ead3b0ce22a892eeb9827/cpp/stringzilla/ngrams.hpp#L41)

```cpp
~ngrams_engine_t() noexcept;
```

##### `queries_count`

Queries filed, the first axis of every overlap output, or zero to only sketch.

[ngrams.hpp:67 ↗](https://github.com/ashvardanian/StringZilla/blob/cb8d956a24817c2fd65ead3b0ce22a892eeb9827/cpp/stringzilla/ngrams.hpp#L67)

```cpp
std::size_t queries_count() const noexcept;
```

##### `widths_count`

Window widths, the last axis of every overlap output.

[ngrams.hpp:70 ↗](https://github.com/ashvardanian/StringZilla/blob/cb8d956a24817c2fd65ead3b0ce22a892eeb9827/cpp/stringzilla/ngrams.hpp#L70)

```cpp
std::size_t widths_count() const noexcept;
```

##### `overlaps`

Shares of every query's distinct N-grams each candidate holds, per width, into a \[queries, candidates, widths] block with a unit-strided width axis.

[ngrams.hpp:85 ↗](https://github.com/ashvardanian/StringZilla/blob/cb8d956a24817c2fd65ead3b0ce22a892eeb9827/cpp/stringzilla/ngrams.hpp#L85)

```cpp
status_t overlaps(
    strings_view_t candidates,
    float radius,
    std::span<float> shares,
    std::size_t shares_query_stride,
    std::size_t shares_candidate_stride,
    sz_stream_t stream = nullptr) noexcept;
```

#### Parameters

| `candidates` | in | The texts probed against the queries. |
| - | - | - |
| `radius` | in | The share of a query's distinct N-grams a pair may miss and stay exact. |
| `shares` | out | The block, device-reachable on a device. |
| `shares_query_stride` | in | Bytes from one query's plane to the next. |
| `shares_candidate_stride` | in | Bytes from one candidate's row to the next. |
| `stream` | in | Null on the CPU, or the stream of the engine's device. |

#### Statuses

- `unexpected_dimensions_k` `shares` is shorter than the block.

##### `sketches`

One MinHash sketch of `slots` bytes per text of `texts`, at the engine's widths.

[ngrams.hpp:106 ↗](https://github.com/ashvardanian/StringZilla/blob/cb8d956a24817c2fd65ead3b0ce22a892eeb9827/cpp/stringzilla/ngrams.hpp#L106)

```cpp
status_t sketches(
    strings_view_t texts,
    std::size_t slots,
    std::span<std::uint8_t> sketches,
    std::size_t sketches_stride,
    sz_stream_t stream = nullptr) noexcept;
```

#### Parameters

| `texts` | in | The texts to sketch. |
| - | - | - |
| `slots` | in | Bytes of one sketch. |
| `sketches` | out | The sketches, device-reachable on a device. |
| `sketches_stride` | in | Bytes from one sketch to the next. |
| `stream` | in | Null on the CPU, or the stream of the engine's device. |

#### Statuses

- `unexpected_dimensions_k` [`sketches`](#sketches) is shorter than the sketches.

##### `make`

Files `queries` at every width in `window_widths` with the best of `capabilities`.

[ngrams.hpp:55 ↗](https://github.com/ashvardanian/StringZilla/blob/cb8d956a24817c2fd65ead3b0ce22a892eeb9827/cpp/stringzilla/ngrams.hpp#L55)

```cpp
expected<ngrams_engine_t> make(
    strings_view_t queries,
    std::span<std::size_t const> window_widths,
    std::size_t candidates_budget,
    sz_allocator_t *allocator = nullptr,
    sz_capability_t capabilities = default_capabilities(),
    sz_stream_t stream = nullptr) noexcept;
```

#### Parameters

| `queries` | in | The texts whose N-grams are filed, or none to only sketch. |
| - | - | - |
| `window_widths` | in | Window widths in bytes, each at least one, the last axis of every overlap output. |
| `candidates_budget` | in | Candidates one round may carry where a backend keeps state per candidate, zero asking for its default. |
| `allocator` | in | Source of the engine's blocks, kept until it is destroyed, or null for the unified allocator of `capabilities`. |
| `capabilities` | in | Capabilities to pick from. |
| `stream` | in | Null on the CPU, or the stream of the device `capabilities` describes. |
