These functions are used to arrange a walk across a 2D matrix to use cache more efficiently. They implement a space-filling curve in 2D. A space-filling curve gives you a single integer to index a two-dimensional array. If you have 2D tiles, then you would find the Hilbert index of each tile and sort by that index in order to improve cache use. Given an x and y value, translate it into a Hilbert z-value.

encode_hilbert(x, y)

Arguments

x

An integer for one axis.

y

An integer for the other axis.

Value

A z-value to index the two of them.