# Platform Notes

> A sequence_index_t searches proteins by global alignment, DNA and RNA by shifted overlap on either strand, and UTF-8 text by window containment in any case.

`#include <usearch/geospatial_index.hpp>` 3.0.0-rc.1 · cabb6603

### Sequence Indexes

A `sequence_index_t` searches proteins by global alignment, DNA and RNA by shifted overlap on either strand, and UTF-8 text by window containment in any case. Its sequences cross as one `tape_view<std::uint8_t>`, the Apache Arrow `Binary` layout of bytes end to end around one more 32- or 64-bit offset than entries, so the two runs of an Arrow column pass as they are.

```cpp
auto [index, index_status] = us::sequence_index_t::init_ram({.metric = usearch_sequence_metric_utf8_containment_k});
std::uint8_t const words[] = {'k', 'i', 't', 't', 'e', 'n', 's', 'i', 't', 't', 'i', 'n', 'g'};
std::uint64_t const offsets[] = {0, 6, 13};
us::status_t const inserted = index.insert(keys, {words, offsets});

auto [arena, arena_status] = us::arena_t::make();
auto [matches, status] = index.search({words + 6, std::span(offsets).first(2)}, 1, arena);
auto [stored, stored_status] = index.get(keys[1], arena); // stored.entry(0) spans "sitting"
```

`count` answers a key’s entries with their total and largest byte lengths. A metric names everything about its sequences; `usearch_sequence_costs_t`, similarities between raw bytes with a gap cost, replaces a metric’s own costs, and `utf8_containment` takes none. A checkpoint records the costs, so loads and views take none, and a stored text reads back folded. Protein alignments and containments keep a sketch of `sketch_bytes` in front of each sequence, 512 when the init names none; searches walk the sketches first and the score from what that walk found, and `sequence_search_config_t::hints` starts a RAM search from an earlier one’s matches. The receivers, reports and plans work as the dense ones do: `refine` and `reshard` take a `sequence_refine_plan_t` or a `sequence_reshard_plan_t` and answer a `usearch_refine_report_t`.

### Shape Indexes

A `shapes_index_t` searches 3D point clouds of any size, like molecules, conformers and protein backbones, invariant to rotation and translation, and the unordered kinds to reflection and point order too. Its tape holds `[x, y, z]` points end to end, with offsets that count points, as an Arrow `List` column lays them out:

```cpp
auto [index, index_status] = us::shapes_index_t::init_ram( // Chamfer over f32 points
    {.metric = usearch_shapes_metric_chamfer_k, .quantization = usearch_scalar_f32_k});
float const points[5][3] = {{0, 0, 0}, {1.1f, 0, 0}, {0, 0, 0}, {1.5f, 0, 0}, {0, 1.5f, 0}};
std::uint64_t const offsets[] = {0, 2, 5}; // a pair and a triple
us::status_t const inserted = index.insert<float>(keys, {&points[0][0], offsets});

float const probe[2][3] = {{0, 0, 0}, {1, 0, 0}};
std::uint64_t const probe_offsets[] = {0, 2};
auto [arena, arena_status] = us::arena_t::make();
auto [matches, status] = index.search<float>({&probe[0][0], probe_offsets}, 1, arena);
```

The metrics are Chamfer, Hausdorff, Gromov-Wasserstein, Wasserstein-Procrustes and Warping-Procrustes, over `f16` or `f32` storage, whatever scalar the points arrive in. `protein-superposition` and `rna-superposition` compare ordered backbones, tell mirror images and reversed chains apart. A non-zero `points` in `usearch_shapes_init_ram_t` freezes every shape’s point count. `get<T>` converts each shape to the scalar it is asked for and answers it in its inserted pose, and `count` reports a key’s total and largest point counts.

### Geospatial Indexes

A `geospatial_index_t` searches observations on and above the Earth, like photos, video frames, drone footage and sensor fixes. `usearch_geospatial_observation_t` is the library’s own eleven doubles, so a span of them crosses with no copy; a field no device recorded stays NaN, which only widens the tests that read it:

```cpp
double const unrecorded = std::numeric_limits<double>::quiet_NaN();
auto at = [=](double latitude, double longitude) noexcept {
    return usearch_geospatial_observation_t {latitude,   longitude,  unrecorded, unrecorded, unrecorded, unrecorded,
                                             unrecorded, unrecorded, unrecorded, unrecorded, unrecorded};
};
auto [index, index_status] = us::geospatial_index_t::init_ram({});
usearch_geospatial_observation_t const stops[3] = {at(51.5308, -0.1238), at(51.5320, -0.1233), at(51.5033, -0.1196)};
us::status_t const inserted = index.insert(keys, stops);

auto [arena, arena_status] = us::arena_t::make();
auto [nearby, status] = index.within({stops, 1}, usearch_geospatial_relation_near_k, {.metres = 500}, arena);
assert(nearby.view.offsets[1] == 2); // both stops within 500 metres, in chord metres
```

`within` reports every entry the relation admits inside the radius, however many, while `search` ranks the `wanted` nearest, a zero `metres` ranking by distance alone. The relation is an argument of each call: `near` widens the radius by both positions’ accuracies, `sees` and `seen` test the view cones, and `visible` tests a line of sight over the terrain the handle was built with, which `us::geospatial_terrain(handler, grid)` fills on demand. The index keeps that handler for its whole life and calls it from the executor’s threads at once, so its call operator is `const`. `get` answers a key’s observations within the stored rounding.

### Left Unbound

These C entry points also take a deferred completion, but the SDK calls them blocking, whatever receiver you hold:

- The `load_*` family, `view_nvme`, `load_nvme`, `metadata_read` and `metadata_read_buffer`, with each one’s `executor` argument choosing where it fans out.
- Cursor and search-stream openings, which name no executor, and their pulls, which run on the receiver’s.

`init_ram`, `init_vram` and `view_ram` block in C as well. No verb throws, so a caller wanting exceptions wraps `status_t` in one place of its own.

### Design

- **A thin layer over the C ABI.** Every name follows `c/usearch/`: a C verb `usearch_dense_<verb>` is a `<verb>` here, each header mirrors one C header, and a verb’s argument struct becomes its `dense_*_config_t` or is taken as is. Enums are the C enums, never strings.
- **The receiver chooses, the verb stays.** The index runs a verb on the calling thread, `on(executor)` blocks on an executor, and `deferred(executor)` submits it, all with the same arguments.
- **Deferred calls use the language’s own idioms.** `status` polls the status word, `wait()` blocks on it, and `co_await call.wait(loop)` suspends and re-polls through the caller’s scheduler, as Rust’s `Deferred` re-wakes itself through its `RawWaker`, since the library has no wake-up.
- **No life of its own.** The SDK starts no threads, keeps no queues and caches nothing; destroying a `deferred` waits for the call first.
- **Arenas are the caller’s, reused, never shared.** Every output whose length scales with the call lands in an arena the caller passes, and the answer is a view over it.
- **Nothing costs anything until it is used.** A blocking call allocates nothing, keeping its outcome and outputs on the stack; a deferred submission allocates nothing, keeping them in the immovable `deferred` the caller holds; an awaiter lives in the coroutine frame, and the scheduler stores two words, a function and a state pointer.
- **Callers pass memory, never an allocator.** No allocation callback crosses into the library: payload belongs to the index, placed by its constructor’s residency, and scratch belongs to the executor.
- **Callbacks cannot throw.** Every handler concept requires a `noexcept` call, and its trampoline is `noexcept`.
- **Shared pieces, no base classes.** Statuses, expected values, deferred calls, owners, plans, tapes, executors and arenas live in `usearch/types.hpp`, held as members, and each index header adds only its own verbs.

| Path | C++ | Rust |
| - | - | - |
| Blocking call | 0 | 0 |
| Refusal before the call | 0 | 1 error |
| Deferred submit and wait | 0: the `deferred` lives with the caller | 0: the `Deferred` is pinned where it is polled |
| Each callback | 0 | 0 |

## API

### Functions

#### `geospatial_terrain`

The `grid` filled on demand by `handler`, which every index naming it keeps for its life and calls from the executor's threads.

[geospatial_index.hpp:80 ↗](https://github.com/unum-cloud/USearch/blob/cabb660355b45ed0d6ade2dc86ca58be01d61e29/cpp/usearch/geospatial_index.hpp#L80)

```cpp
template <a_terrain_handler handler_type_>
usearch_geospatial_terrain_t geospatial_terrain(
    handler_type_ & handler,
    usearch_geospatial_terrain_t grid) noexcept;
```
