Code

Wiring load and stats

Wire the new commands into main.go. The change is small — two case lines and two lines of usage text — but the panel shows the whole file so you can see where they land.

$ algo gen -n 1000 -seed 42
wrote 1000 items to library.jsonl (seed=42, order=shuffled, dup-rate=0.00)

$ algo load
loaded 1000 items from library.jsonl
slice: len=1000 cap=1024 — 24 slots reserved and unused

A thousand items, and room reserved for 1024. Those 24 empty slots are the price of the next 24 appends being cheap. That is the trade: memory for time, and it recurs for the rest of the course.

In a real system: when the header costs more than the data

transit — a working Vilnius public-transport planner — stores its graph as one flat array rather than an array of arrays. Its source says why in a sentence: at ~400,000 edges a slice-of-slices would waste megabytes on headers alone.

Do the arithmetic yourself. The graph has 206,875 nodes. If each held its own []int list of neighbours, that is 206,875 slice headers at 24 bytes each:

206,875 × 24 B ≈ 4.96 MB

Five megabytes containing not one edge — just pointers, lengths and capacities. That is before the edges themselves, and before the fact that 206,875 separate little arrays would be scattered across memory instead of sitting back to back.

This is a design note, not a measurement

transit's authors did not measure this — it is a decision made by arithmetic, and that is how it is recorded in their code. The number above is calculated too, not measured. Keep the distinction: step 2's table is a measurement, this paragraph is an argument. Both are useful; only one of them is evidence.