Home▸Algorithms & AI▸Space-Filling Curves: Hilbert and Z-Order Query Runs on a Grid (2D)

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

Two coloured grids side by side, one ordered along the Hilbert curve and one along the Z-order curve, with a moving query rectangle and the runs it breaks into. Same index functions, cluster counting and checks as the 3D board.

Algorithms & AI2DModerate60 FPS📱 Mobile-adapted🟠 Blender⇄ 3D version
Space-Filling Curves: Hilbert and Z-Order Query Runs on a Grid (2D) ↗ Open standalone

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.

⚙ Under the hood

Two coloured grids side by side, one ordered along the Hilbert curve and one along the Z-order curve, with a moving query rectangle and the runs it breaks into. Same index functions, cluster counting and checks as the 3D board.

Space-Filling CurveHilbert CurveZ-Order CurveMorton CodeRange QuerySpatial IndexDatabase Locality

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)