v1.7.2Spatial IndexBSD-2-Clause

Multi-dimensional spatial database engine using Morton code (Z-order) indexing for lightning-fast 3D/4D coordinate and bounding-box queries in pure C. Canonical header is <ttypt/pointcfg.h>.

GitHub
git clone https://github.com/tty-pt/libislet

libislet logo

libislet

npm C99 BSD-2-Clause Spatial (Morton) Recall Kernel Space Axis

Multi-dimensional spatial database engine using Morton code (Z-order) indexing for lightning-fast 3D/4D coordinate and bounding-box queries in pure C. Canonical header is <ttypt/pointcfg.h>.

1. Quickstart

Index 3D/4D entity positions and query a bounding box in under 20 lines:

#include <stdio.h>
#include <stdint.h>
#include <ttypt/pointcfg.h>

int main(void) {
    islet_init();
    uint32_t world = islet_open(NULL, NULL, 0xFFFF);

    // Index entity positions in 3D space: (x, y, z) -> entity_id
    int16_t pos[3] = {120, 45, -300};
    uint32_t entity_id = 99;
    Point3_2.put(world, pos, entity_id);

    // Query 50x50x50 bounding box around the entity
    int16_t box_min[3] = {100, 20, -320};
    uint16_t box_len[3] = {50, 50, 50};
    uint32_t iter = Point3_2.iter(world, box_min, box_len);

    int16_t hit_pos[3];
    uint32_t hit_id;
    while (Point3_2.next(hit_pos, &hit_id, iter)) {
        printf("Found entity %u at (%d, %d, %d)\n", hit_id, hit_pos[0], hit_pos[1], hit_pos[2]);
    }

    return 0;
}

Compile and link:

cc voxel_query.c $(pkg-config --cflags --libs libislet) -o voxel_query

2. Core API Reference

The recommended API surface uses configuration descriptors (Point<D>_<B>, e.g. Point3_2 for 3D and Point4_2 for 4D int16_t coordinates):

OperationSignatureDescription
Point3_2.putPoint3_2.put(db, pos[3], ref)Store a 32-bit reference at 3D coordinates
Point3_2.getPoint3_2.get(db, pos[3])Retrieve reference stored at 3D coordinates
Point3_2.iterPoint3_2.iter(db, min[3], len[3])Open a cursor across a rectangular 3D bounding box
Point3_2.nextPoint3_2.next(pos_out, ref_out, iter)Advance bounding-box cursor (1 valid, 0 done)
Point3_2.fill_bboxPoint3_2.fill_bbox(db, min, len, set)Stream all 3D box refs directly into a sealed recall candidate set
Point4_2.putPoint4_2.put(db, pos[4], ref)Store a 32-bit reference at 4D coordinates (space + scale/time)
Point4_2.fill_bboxPoint4_2.fill_bbox(db, min, len, set)Stream all 4D hypercube refs into a sealed recall set
islet_box_is_emptyint islet_box_is_empty(db, dim, min, len)Fast O(log N) Morton Z-interval emptiness check without full box scan
morton_quad_* / islet_quad_map_*<ttypt/islet_quad.h>2D hierarchical quadtree Morton keys ([0..16] levels) and open-addressed spatial hash map with tombstone-free backward-shift deletion (islet_quad_map_del), probed lookups (islet_quad_map_get_probed), and cluster stats (islet_quad_map_inspect)

๐Ÿ‘‰ For AVX2 SIMD Morton codecs, multi-value cells, and benchmarks, see docs/PERF.md.


3. Morton Z-Order Spatial Indexing

libislet flattens multi-dimensional space into linear integers using Morton Z-order space-filling curves:

  Y โ–ฒ
  3 โ”‚  10   11 โ”‚  14   15
  2 โ”‚   8    9 โ”‚  12   13
    โ”œโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”ผโ”€โ”ผโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”ค
  1 โ”‚   2    3 โ”‚   6    7
  0 โ”‚   0    1 โ”‚   4    5
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ X
        0    1    2    3
  • Bits Interleaved: Coordinates $(X, Y, Z)$ are bit-interleaved into a single 64-bit integer, preserving spatial proximity in linear memory.
  • Logarithmic Seeks: 3D bounding box queries turn into fast binary searches along the curve, skipping aligned empty space in single jumps.
  • Sub-Microsecond Speed: Point insertions and range queries execute at CPU cache speeds with zero heap allocations.

4. corm CLI Multi-Axis Integration

libislet attaches directly to the corm CLI tool as the @islet spatial axis:

# Ingest 3D coordinates into database:
corm -p "120,45,-300:player_99" world.db@islet:a:s

# Spatial bounding box query via corm CLI:
corm -X "islet" --islet="bbox:100,20,-320,50,50,50" world.db@islet:a:s

libislet functions as the canonical Space Axis for spatial queries and recall composition:

  • Core Storage Engine: Backed by libcorm for sorted Morton-code map indexing.
  • Cross-Axis Recall Kernel: Composes spatial bounding boxes (Point3_2.fill_bbox, Point4_2.fill_bbox) with sibling axes: libjoint (Time), liblemma (Text), and libsepal (Meaning).

5. Installation & Build

Prebuilt Packages

Prebuilt packages are distributed from tty.pt for Linux (APT / Alpine / Arch / Fedora-RHEL), macOS (Homebrew), Windows (winget / MSYS2), and OpenBSD, and mobile static sysroots for Android (https://tty.pt/android/ โ€” arm64-v8a, armeabi-v7a, x86_64) and iOS (https://tty.pt/ios/ โ€” libislet.xcframework). Follow the installation instructions and use libislet as the package name.

Build from Source

Builds use shared libstele rules (include ttypt/include.mk):

make                  # builds lib/libislet.so
make test             # run unit, integration, and stress tests
sudo make install     # install headers and library to system

6. JavaScript & WebAssembly Bindings (@tty-pt/islet)

Official Node.js and Browser WebAssembly bindings are colocated in npm/:

  • Universal Engine: Native Node-API (.node) and pre-compiled WebAssembly (dist/islet.wasm) for 2D/3D Morton code encoding and bounding-box queries.
  • Spatial Use Cases: Coworking floorplans, seat map selection, canvas viewport entity culling at 120 FPS.
  • C Development Headers: Install via npm install @tty-pt/islet (from npm or https://tty.pt/npm/) and consume headers from node_modules/@tty-pt/islet/include.

๐Ÿ‘‰ For complete TypeScript usage, spatial indexing guides, and API reference, see npm/README.md.

License

BSD 2-Clause License. Copyright (c) 2025, tty-pt. See LICENSE.

Maintained by:tty-pt