The candidate ladder wants the nearest tier of real words - and the index can produce it without generating a single edit. Today you turn a radius search into distance tiers and get the same candidates the generator did.
Produce the nearest non-empty tier of candidates from the BK-tree, matching the generator's known1 or known2.
The candidate ladder from chapter four asked for the nearest tier of real words and
got them by generating edits. The index gives the same tiers directly: a radius-1
search is exactly the one-edit real words (known1), and a radius-2 search that adds
nothing new at radius 1 gives the two-edit tier (known2). IndexCandidates("teh")
returns tea, ten, the - the very list the generator produced, now found by
pruned tree lookups instead of hundreds of thousands of string edits.
This is the swap the whole chapter was building toward: same candidates, same tiers,
a completely different engine underneath. Because you proved IndexNearby equals
Nearby, and known1/known2 also equal Nearby, all three agree by construction
Correct and confirms the
corrections are identical.func (d *Dictionary) IndexCandidates(word string) []string {// known word? -> [word]// else IndexNearby(word, 1); if non-empty, that is the tier// else IndexNearby(word, 2)// else [word]}