Database 02: The Index

The address book sitting over last lesson’s file. Follows Database 01: The Append-Only File, which left every read scanning the whole file, and hands off to Pages.
Before you start. This series builds a small database of our own: a program that saves pairs of a key (a name you look something up by) and a value (what’s stored under that name). Ours already saves every change safely, by adding a new line to the end of a file on disk (the disk being the part of the computer that keeps data after the program stops running), so a crash mid-write loses nothing already saved; and it deletes a key by writing a marker over it rather than erasing anything. But asking it “what is the value for this key” has no shortcut yet: it reads the file one byte (one unit of stored data) at a time from the start, checking every line until it finds the answer or runs out of file.