Hilbert curves and key locality
medium 4 minA space-filling curve assigns an order to cells so a spatial region can often be read as a small set of key ranges.
Video lesson · Chapter 1 of 5
A square map becomes a line of keys
Neighbours on a map, far apart in key order
1:07Reel
Theory
Read or listen first. About 1 min.
What it is
To assign a key on a Hilbert curve, visit spatial cells in a recursive order. Nearby positions along the traversal tend to represent nearby areas of the map.
The two ends of a Hilbert traversal touch
Why it exists
A point also has neighbours across edges the traversal does not directly cross. A geographic query can therefore need several separated intervals of keys.
Words to know
- Spatial locality
- The extent to which locations near one another stay close in an index or traversal.
How it works
Step through the idea, or press Play.
Visit cells. Trace four quadrants in a U-shaped order.
Understand it
Worked example
Hilbert curves and key locality in practice
Consider four quadrants visited in a U. The first and last touch along an edge but are far apart in key order. A nearest-neighbor lookup therefore cannot rely on the next or previous key alone.
Related case
Find every charger across a cell boundary
A driver near the edge of a grid cell requests chargers within 800 metres. The closest charger sits across the street in another cell.
Fetch intersecting cells and check candidates.