islet_morton(3)islet

NAME

islet_morton - Morton code helpers

- Encode and decode Morton (Z-order) codes for spatial indexing.

SYNOPSIS

Functions

static uint64_t morton_set_1 (int16_t *p)

Encode multi-dimensional coordinates into Morton codes.

static uint64_t morton_set_2 (int16_t *p)

Encode a 2D point. See morton_set_1() for the family docs.

static uint64_t morton_set_3 (int16_t *p)

Encode a 3D point. See morton_set_1() for the family docs.

static uint64_t morton_set_4 (int16_t *p)

Encode a 4D point. See morton_set_1() for the family docs.

static uint64_t morton_set_2_32 (int32_t *p)

Encode a 2D x 32-bit point. Dense full-64-bit layout (2 x 32 bits); part of the dense config family, not the legacy 16-bit-lane sparse layout that morton_set_2() uses.

static void morton_get_1 (int16_t *pos, uint64_t code)

Decode a Morton code into a multi-dimensional coordinate.

static void morton_get_2 (int16_t *pos, uint64_t code)

Decode a 2D Morton code. See morton_get_1() for the family docs.

static void morton_get_3 (int16_t *pos, uint64_t code)

Decode a 3D Morton code. See morton_get_1() for the family docs.

static void morton_get_4 (int16_t *pos, uint64_t code)

Decode a 4D Morton code. See morton_get_1() for the family docs.

static void morton_get_2_32 (int32_t *pos, uint64_t code)

Decode a 2D x 32-bit Morton code. Inverse of morton_set_2_32().

Detailed Description

Encode and decode Morton (Z-order) codes for spatial indexing.

Morton codes interleave the bits of multi-dimensional coordinates to create a single linear ordering that preserves spatial locality. For example, in 2D:

Coordinate (x=5, y=3):

In 3D, the pattern extends with z bits in every third position.

Coordinate System:

The conversion from signed to unsigned preserves ordering: -32768 โ†’ 0, -32767 โ†’ 1, ..., 0 โ†’ 32768, ..., 32767 โ†’ 65535

Note

Currently optimized for 3D/4D with fast bit-manipulation algorithms (stride-3 packing for dims 1-3, dense stride-4 packing for dim 4, dense stride-2 packing for the 2D x 32-bit config). 1D/2D/3D codes are bit-identical to v0.5.0; 4D codes are new. When compiled with -mbmi2 the encode and decode kernels use PDEP/PEXT for a 2-3ร— speedup over the scalar path (default-on, opt out with -DISLET_USE_PDEP=0).

All dimensions share the uint64 key space: use one dimension per database.

See also

Islet core API

Point utilities

Function Documentation

void morton_get_1 (int16_t * pos, uint64_t code) [inline], [static]

Decode a Morton code into a multi-dimensional coordinate. These per-dimension specializations are the decode API. Each decodes exactly one dimension count; there is no runtime dim argument. Inverse of the matching morton_set_N().

Parameters

pos Output point. Array of int16_t with space for the dimension count of the function used.
code Morton code to decode (64-bit).

Note

The output coordinates will be in range -32768 to 32767 (int16_t).

Warning

Decoding a Morton code that wasn't created by morton_set_N() with valid coordinates may produce unexpected results (garbage coordinates).

Example:

uint64_t code = 0x123456789ABCULL;  // Some Morton code
int16_t point[3];
morton_get_3(point, code);
// point now contains the decoded coordinates

See also

morton_get_1 morton_get_2 morton_get_4

morton_set_1 morton_set_2 morton_set_3 morton_set_4

islet_iter

void morton_get_2_32 (int32_t * pos, uint64_t code) [inline], [static]

Decode a 2D x 32-bit Morton code. Inverse of morton_set_2_32().

Parameters

pos Output point. Array of int32_t with space for 2 elements.
code Morton code to decode (64-bit, dense layout).

uint64_t morton_set_1 (int16_t * p) [inline], [static]

Encode multi-dimensional coordinates into Morton codes. These per-dimension specializations are the encode API. Each encodes exactly one dimension count; there is no runtime dim argument to branch on, so the compiler sees a fully unrolled expression.

Algorithm (dims 1-3):

1.
Convert signed int16_t to unsigned uint16_t (add 32768)
2.
Spread each 16-bit coordinate across 48 bits (every 3rd bit)
3.
Combine: code = spread(x) | spread(y)<<1 | spread(z)<<2

Dim 4 uses dense stride-4 packing that fills all 64 bits. Dims 1-3 code values are bit-identical to v0.5.0; 4D codes are new.

Parameters

p Input point. Array of int16_t with at least the dimension count of the function used. Coordinates range from -32768 to 32767.

Returns

64-bit Morton code. For 1-3D, uses 48 bits (16 bits per dimension) with the upper 16 bits reserved; 4D fills all 64 bits.

Example (3D):

int16_t point[3] = {10, -5, 100};
uint64_t code = morton_set_3(point);
// code now contains the interleaved bit representation

Example (round-trip verification):

int16_t original[3] = {123, -456, 789};
uint64_t code = morton_set_3(original);
int16_t decoded[3];
morton_get_3(decoded, code);
// decoded[0]==123, decoded[1]==-456, decoded[2]==789

See also

morton_set_1 morton_set_2 morton_set_4

morton_get_1 morton_get_2 morton_get_3 morton_get_4

islet_put

islet_get

uint64_t morton_set_2_32 (int32_t * p) [inline], [static]

Encode a 2D x 32-bit point. Dense full-64-bit layout (2 x 32 bits); part of the dense config family, not the legacy 16-bit-lane sparse layout that morton_set_2() uses. Algorithm:

1.
Convert signed int32_t to unsigned uint32_t (add 2^31)
2.
Spread each 32-bit coordinate across 64 bits (every 2nd bit)
3.
Combine: code = spread2(x) | spread2(y)<<1

Parameters

p Input point. Array of int32_t with at least 2 elements. Coordinates range from -2147483648 to 2147483647.

Returns

64-bit Morton code filling all 64 bits (no reserved bits).

Author

Generated automatically by Doxygen for islet from the source code.