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

033122123211300301213302303
DriverCheckedFound in the circleMissedRiderCell that was read
Cells read
9/ 64
the rider's cell and the ring round it
Drivers checked
158/ 200
distance measured to each one
Found in the circle
118
Healthy: within 1.0 km of the rider
Missed
0
none
Rider's cell code
300
cells with the same first digit share a quarter of the map

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

How to search

Cut the map into 64 equal cells. Read only the cells near the rider. A geohash names cells like these.

Where the drivers are

Three drivers in four are in one crowded 2 km square.

The rider
9.0 km
9.0 km
1.0 km

Fixed grid only. Off: the search reads the rider's own 2 km cell and nothing else.

Tip: you can also click the map to move the rider.

Drivers checked, by method

  • Scan every driver200
  • Fixed grid158
  • Quadtree149

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.