build-a-spell-checker / lesson-32.md
Lesson 32 · A fast candidate index

Correcting a document, fast

Close the chapter by running the indexed corrector over a whole passage. Today you build CorrectionsFast and confirm it produces the same report as the slow path, now cheap enough for real text.

The goal

Correct every unknown word in a passage using the index, matching the earlier Corrections output.

Start here - the target
TO DO
Scenario: Fast document correction
Givena dictionary with counts the:1000, cat:500, sat:100, indexed into a BK-tree
WhenCorrectionsFast("teh cat sat") is called
Thenit returns one entry: "teh" at start 0, corrected to "the"
Andits output is identical to Corrections("teh cat sat") from the generator-based path
Background

The document corrector, now on the index: CorrectionsFast walks the unknown tokens of a passage and corrects each with CorrectFast. Its output matches the slow Corrections byte for byte, because every piece underneath was proven equivalent - but it is now fast enough to run over pages of prose without the two-edit generator’s explosion of strings.

That completes the performance arc of the project. From here on, the checker is fast and correct, and the remaining chapter is about the product: turning corrections into a real tool with top-N suggestions, original-case output, line and column reporting, a readable report format, and a personal ignore list. The engine is done; the polish begins.

Make it work
func (d *Dictionary) CorrectionsFast(text string) []Correction {
// like Corrections, but call CorrectFast on each unknown token
}
CheckpointDONE
The whole corrector now runs on the fast index over real passages. Commit and stop here.