If you think you want to use a Hilbert Curve for cache locality (on a square grid), you might want to check out the Z-Order Curve instead - https://en.wikipedia.org/wiki/Z-order_curve . It has less ideal locality properties but can be computed more efficiently.