Lab · Distributed data
Map cells: find what is nearby
A rider wants the drivers within a short distance, out of 200 on the map. Search three ways: measure every driver, read a fixed grid of cells, or read a quadtree. See which cells are read and how many drivers are checked.
Try it
Numbers add up:118 drivers in the circle = 118 found + 0 missed · 158 of 200 drivers checkedThe lab checks this sum as it runs, so a counting mistake would show here.
Controls
Cut the map into 64 equal cells. Read only the cells near the rider. A geohash names cells like these.
Three drivers in four are in one crowded 2 km square.
Drivers checked, by method
Every method finds the drivers it checks that are inside the circle. Read for this search: fixed grid 9 cells, quadtree 73 squares. A careful grid search would read 5 cells and check 155 drivers.
What this model simplifies
- The map is flat and 16 km wide. Real indexes cover a round Earth, where cells get narrower away from the equator.
- The fixed grid reads every cell in the ring, even corner cells that the circle does not touch. A careful grid search skips those.
- Drivers stand still. Real drivers report a new place every few seconds, so their cell must be updated all the time.
- The cell code has 3 digits, and each digit picks 1 of 4 parts. A real geohash character picks 1 of 32 parts, and 6 characters name a cell about 1.2 km by 600 m.
- Reading a cell is free here. In a real system each cell read is a lookup in a database or a cache.
- The quadtree is built once, and splits a square that holds more than 4 drivers. A real one holds far more per square, and splits and merges as drivers move.