Expand description
Sort key encoding for external sort — (tile_id, layer, sort_key).
The sort key packs tile identity, layer ordinal, and feature ordering
into a single u64 for efficient comparison during external merge sort.
§Layout (MSB → LSB)
[4 bits zoom][30 bits tile_id][5 bits layer][25 bits feature_sort]- zoom (4 bits): 0–15 (
max_zoom=15is the project default) tile_id(30 bits): Row-majory * (1 << z) + x. At z15, max value is32768 * 32768 - 1 ≈ 1.07B, which fits in 30 bits (max 1.07B). The previous 29-bit layout silently overflowed at z15.- layer (5 bits): 0–31 (supports up to 31 layers for configurable schemas)
feature_sort(25 bits): Biased signed value (±16M range)
This creates a total ordering: tiles grouped together → layers within a tile → features within a layer.
Functions§
- decode_
layer - Decode the layer ordinal from a sort key.
- decode_
tile_ id - Decode the zoom level and tile ID from a sort key.
- encode
- Encode a tile coordinate + layer + feature sort key into a single
u64. - tile_
id_ to_ xy - Convert a linear tile ID back to (x, y) at a given zoom level.