logo
By Lawrence

12 minutes

Chunk Streaming

This lesson starts from the lab, with every code edit from the earlier lessons undone. RoadProbe can stay.

The chunk ring

Lesson 1.1 showed chunkWindow, which keeps a couple of chunks behind the car and eight ahead, and said the chunk that falls behind is rebuilt as the next one ahead. Here is how the System finds the right place to put it, and why two chunks built at different moments still meet without a crack.

The System keeps a ring of 11 slots. Chunk i always lives in slot i mod 11, the remainder after dividing by 11. Park the car at 1750 m, on lesson 1.1's bridge:

car at 1750 m, chunk 58, window 56 to 66

chunk   56  57  58  59  60  61  62  63  64  65  66
slot     1   2   3   4   5   6   7   8   9  10   0

Drive on to 1770 m and the car enters chunk 59:

car at 1770 m, chunk 59, window 57 to 67

chunk   57  58  59  60  61  62  63  64  65  66  67
slot     2   3   4   5   6   7   8   9  10   0   1

Chunk 67 went into slot 1, the slot chunk 56 just left. The chunk that drops off the back and the one that joins the front are always 11 apart, so they always share a slot. No list moves, and nothing searches for a free slot.

A ring of 11 slots, numbered 0 to 10, each labelled with the chunk it holds for a car at 1750 m. An arrow shows chunk 67 replacing chunk 56 in slot 1 as the car crosses 1770 m.

Continue reading

Unlock the Full Course

Every lesson, the runnable examples, and the finished build — yours to keep.

$5one-time

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search