Skip to content

Hilbert functions in the Lindel DuckDB extension

Function category

Hilbert

2 functions

hilbert_decode

Scalar function Hilbert
Signature
hilbert_decode( encoded_value: <numeric>, num_elements: UTINYINT, return_float: BOOLEAN, return_unsigned: BOOLEAN ) → ANY[ANY]
Arguments (Positional)
Argument encoded_value Type <numeric>
5 concrete types
UBIGINTUHUGEINTUINTEGERUSMALLINTUTINYINT
Mode Positional Description
Argument num_elements Type UTINYINT Mode Positional Description
Argument return_float Type BOOLEAN Mode Positional Description
Argument return_unsigned Type BOOLEAN Mode Positional Description
Description
1 Round-trip an encoded integer back to its components (num_elements, return_float, return_unsigned)
SELECT hilbert_decode(hilbert_encode([10, 20]::UINTEGER[2]), 2, false, true) AS roundtrip;
2 Round-trip signed integer coordinates with return_unsigned = false
SELECT hilbert_decode(hilbert_encode([-10, 20]::INTEGER[2]), 2, false, false) AS roundtrip;
3 Round-trip floating-point values with return_float = true
SELECT hilbert_decode(hilbert_encode([-1.5, 2.25]::DOUBLE[2]), 2, true, false) AS roundtrip;

hilbert_encode

Scalar function Hilbert
Signature
hilbert_encode(values: ANY[ANY]) → ANY
Arguments (Positional)
Argument values Type ANY[ANY] Mode Positional Description
Description
1 Order nonnegative integer coordinates by their Hilbert key
SELECT x, y, hilbert_encode([x, y]::UINTEGER[2]) AS hilbert
FROM (VALUES (1, 1), (1, 2), (2, 1), (6, 7), (7, 6)) AS t(x, y)
ORDER BY hilbert;