THE FOLD / CO-OP / SHARED MEMORY / THE CURVE THAT FILLS THE PLANE
THE CURVE THAT FILLS THE PLANE
one line threads every cell — and keeps neighbors near
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
The Hilbert curve. A single continuous fractal path that visits every cell of a 2n×2n grid exactly once — and never jumps: consecutive cells are always neighbors. It is a space-filling curve, a way to unroll a 2D square into a 1D line.
The magic is locality preservation. Two points close together on the line stay close together on the plane. Row-major scanning (left to right, top to bottom) tears that apart — two cells one row apart are a whole width away in memory. Hilbert doesn’t tear. That is why it is used for cache-friendly memory layouts, spatial database keys (map (x,y) to a 1D index that clusters), image dithering, and R-tree ordering: put spatially near things near in storage, and the cache hits.
LIT verified live: for grids up to 64×64 the index→(x,y) map is a bijection, its inverse (x,y)→index round-trips exactly, and every pair of consecutive indices is Manhattan-distance 1 apart (window.__hilbert). FIG no framing; the bijection, the exact inverse, and the adjacency are all real.
The magic is locality preservation. Two points close together on the line stay close together on the plane. Row-major scanning (left to right, top to bottom) tears that apart — two cells one row apart are a whole width away in memory. Hilbert doesn’t tear. That is why it is used for cache-friendly memory layouts, spatial database keys (map (x,y) to a 1D index that clusters), image dithering, and R-tree ordering: put spatially near things near in storage, and the cache hits.
LIT verified live: for grids up to 64×64 the index→(x,y) map is a bijection, its inverse (x,y)→index round-trips exactly, and every pair of consecutive indices is Manhattan-distance 1 apart (window.__hilbert). FIG no framing; the bijection, the exact inverse, and the adjacency are all real.
2 HOW IT WAS WEAVED · AI + HUMAN
David (human) seated this in WARM CACHE, beside the other locality spheres — the grind domain of keeping the working set hot. The Hilbert curve is the classic trick for a cache-friendly 2D layout. AVAN (AI) built the instrument: the recursive curve, the index probe, the row-major contrast.
The weave: David names the seat (the warm cache); I make the curve fill the grid without ever jumping and show why that keeps memory hot — the index strip in 1D, the drawn curve in 2D, the locality contrast in 3D. The sphere is the seam. Credit: David Hilbert (1891), building on Giuseppe Peano’s first space-filling curve (1890).
The weave: David names the seat (the warm cache); I make the curve fill the grid without ever jumping and show why that keeps memory hot — the index strip in 1D, the drawn curve in 2D, the locality contrast in 3D. The sphere is the seam. Credit: David Hilbert (1891), building on Giuseppe Peano’s first space-filling curve (1890).
3 ONE DIMENSION
The 1D index line 0, 1, 2, …, N−1 — the order the curve visits cells. Slide along it and the highlighted plane cell (shown in window 4) moves only one step at a time. The line and the square are the same walk.
4 TWO DIMENSIONS · INTERACTIVE
The Hilbert curve drawn at order p. Probe an index to see its cell; the curve never breaks contact with itself. Toggle the row-major scan to see the alternative that jumps a full row every wrap.
5 THREE DIMENSIONS + AVAN’S INVERSE
The curve lifted into 3D: x, y, and the 1D index as height. The green ribbon climbs smoothly — a small step in height is always a small step in the plane.
AVAN’s addition (the inverse-companion): the magenta ribbon is the row-major layout on the same grid — the naive inverse. Both are bijections between the line and the square; the difference is entirely in the inverse’s behavior. Row-major maps the square to the line by tearing every vertical neighborhood apart — two cells stacked vertically land a full width apart in 1D, so the magenta ribbon leaps across the whole plane on every row wrap. Hilbert’s inverse keeps the neighborhoods intact: nowhere does it leap. That is the real inverse here — not a mirror, but the other direction of the same map, and the whole point of the curve is that its inverse doesn’t shred locality the way the obvious one does. Green never jumps; magenta jumps a full width every wrap. Same bijection, opposite treatment of what’s near.
LIT A genuine Hilbert curve (bit-manipulation d2xy / xy2d). Verified live: the index↔(x,y) map is a perfect bijection over the grid (round-trips), and consecutive indices are always grid-adjacent (Manhattan distance exactly 1). The locality win — a 1D window maps to a far tighter 2D bounding box than row-major — is measured live (verifiable: window.__hilbert.bijection && adjacencyManhattan1 && localityWin).
FIG 'Fills the plane' is the picture; the bijection, the unit-step adjacency, and the locality advantage are exact. It really is used to lay out memory and spatial indexes for better cache behaviour.
FIG 'Fills the plane' is the picture; the bijection, the unit-step adjacency, and the locality advantage are exact. It really is used to lay out memory and spatial indexes for better cache behaviour.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of SHARED MEMORY · David Lee Wise (ROOT0), with AVAN