Hilbert (left) and Z-order (right) grids
Average runs against window side

Space-Filling Curves: Hilbert and Z-Order Query Runs on a Grid (2D)

A database stores a two-dimensional grid of records in one-dimensional order along a space-filling curve. A rectangular range query then touches the records in several separate runs, and every run costs a disk seek. Slide a query rectangle across a grid ordered by the Hilbert curve and by the Z-order (Morton) curve and count the runs: Hilbert needs about the half-perimeter divided by two runs, Z-order needs noticeably more. Change grid size, window width, window height and the seek cost and watch the total access cost. A Blender-built storage board with numerical checks.

Made with 🟠 Blender