Code

algo gen — data you can reproduce

There is nothing to measure until there is data. algo gen makes it.

Create gen.go (see the panel). It adds your first command:

algo gen [-n N] [-seed S] [-o FILE] [-sorted|-reverse|-shuffled] [-dup-rate R]

Titles are built, not drawn from a word list

Two syllable tables — 15 consonants and 8 vowels — give 120 syllables. A three-syllable word is one of 1,728,000; a four-syllable one is one of 207,360,000. Twenty lines of code, no data file, and a million distinct titles:

$ algo gen -n 1000000 -seed 1 -o m.jsonl
wrote 1000000 items to m.jsonl (seed=1, order=shuffled, dup-rate=0.00)

items=1000000 distinct=1000000 duplicate-titles=0 (0.00%)
longest shared prefix among neighbours: 11 runes  "Čėkobėču Kugū" / "Čėkobėču Kuta"

Look at the last line. Because the tables are small, titles share long prefixes — eleven letters in common here. That is not decoration: searching by the start of a title, in lesson 10, would be far too easy if every title began differently.

-seed — why a measurement without it is worthless

The same -seed gives you the same library:

$ algo gen -n 1000 -seed 42 -o a.jsonl && algo gen -n 1000 -seed 42 -o b.jsonl
$ cmp a.jsonl b.jsonl && echo IDENTICAL
IDENTICAL

Without it, two measurements would be measuring two different libraries and the difference between them would mean nothing. With it you can change one thing — the algorithm — and know that is all that changed.

-sorted — the highest-value flag in the course

You write it now; it pays off three times:

  • lesson 7 — sorted data is insertion sort's best case;
  • lesson 8 — the same data is quicksort's worst case if you pick the pivot naively (O(n²));
  • lessons 11–12 — sorted data degenerates a binary search tree into a plain list. Rescuing exactly that is what lesson 12 is for.

Three different lessons, one flag, written on day one.

-dup-rate adds repeated titles — you will want them in lesson 10 (collisions) and lesson 8 (sort stability). At -dup-rate 0 the titles are guaranteed distinct: the generator redraws collisions.