Usage

Quick Start

The simplest case - 2D data:

using BijectiveHilbert
encoder = Simple2D(Int)
h = encode_hilbert(encoder, [x, y])

Choose Your Encoder

2D data

Simple2D requires no setup - just specify the index type:

encoder = Simple2D(Int64)

N-D, same-size axes

SpaceGray is the fastest N-D encoder. All axes must be the same power-of-two size:

# 4D space, each axis 0-7 (3 bits = 2^3 = 8 values)
encoder = SpaceGray(Int64, 3, 4)

GlobalGray and FaceContinuous use the same interface but produce different curve patterns:

encoder = GlobalGray(Int64, 3, 4)
encoder = FaceContinuous(Int64, 3, 4)

N-D, different-size axes

Compact handles axes of different sizes (each must be a power of two):

# 3D space: axis 1 is 0-7 (3 bits), axis 2 is 0-3 (2 bits), axis 3 is 0-15 (4 bits)
encoder = Compact(Int64, [3, 2, 4])

Encode and Decode

Convert a point to a Hilbert index and back:

point = [2, 1, 7, 3]
hilbert_index = encode_hilbert(encoder, point)

point_out = zeros(Int, 4)
decode_hilbert!(encoder, point_out, hilbert_index)
@assert point_out == point

For zero-based indexing, use the _zero variants:

point = [1, 0, 6, 2]
hilbert_index = encode_hilbert_zero(encoder, point)
decode_hilbert_zero!(encoder, point_out, hilbert_index)

Performance Tips

  • Use StaticArrays.MVector for the point vector when encoding/decoding in a tight loop
  • The 1-based functions are thin wrappers around the 0-based implementations