Index

Module 05 · From ScratchDatabase

Database 02: The Index

The Index
The Index · Open board

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.

Continue reading with a plan

The first three lessons of every track are free. This lesson is included with a plan, which unlocks every lesson, board, video, lab and paper for one price.

View plans →Already a member? Sign in

Review From Scratch →

Saved in this browser, and to your account when you sign in.