Fable
The survey team built an index table that did not require measuring the whole territory every time
The border survey team processes hundreds of thousands of terrain sample maps each year. Every time a new landform report arrives, the old rule is to compare it one by one against all previous reports to see if there are similar hills, river valleys and passes.
Reports piled up more and more, and a single comparison went from taking the time of a cup of tea to half a day. The front line urgently waited for results while the back office was still flipping through old maps. The captain said to add people, so twenty people sat in one surveying room, each with a stack of maps, comparing on their own.
What makes it harder is that new reports often don't require exact matches. The commander asks: 'Is there any terrain near here similar to this forest?' Being off by a few dozen meters doesn't matter—rough similarity is enough. But the one-by-one comparison method calculates by exact distance, so every old map has to run a full computation.
A young surveyor on the team had done numerical analysis. He noticed that the reason whole-territory comparison was slow was not that a single computation was heavy, but that every time all old reports had to be reloaded and re-sorted. If the old reports were pre-indexed by terrain features, a new query would only need to find the closest cluster in the index.
He first used a compression code to compress the terrain features of each old report into a short code, then sorted the reports into different buckets by code similarity. At query time, he first computed the code of the new report, found the corresponding bucket, and compared only within that bucket. Anything outside the bucket was skipped.
The first version only split into buckets; accuracy was acceptable but occasionally missed edge reports. He added another layer: besides comparing within the same bucket, also look at adjacent buckets. Reports in adjacent buckets might also be close enough, only their encoding happened to land near the dividing line.
He pushed compression encoding to the extreme: each report's terrain features were compressed from several hundred numbers down to a few dozen. During search, compressed codes were compared first, and only the few reports with similar compressed codes were decompressed for a full comparison.
Later this indexing bench was made into a toolbox that could be called up at any time. The team could choose compression precision and bucket granularity themselves; they could adjust among accuracy, speed and memory without having to read the report from scratch each time. The survey captain finally abolished the rule of full comparison: the soul of comparison is not guaranteeing that every item is seen, but using the least effort to find the most correct few. Later the survey team taught this indexing bench to new recruits. The mistake new recruits most easily made was treating speed as the only goal, making buckets too coarse, so similar valleys were missed; or treating precision as the only goal, making buckets too fine, and falling back to the old slow-query path. The captain required them to adjust according to the battle situation: urgent reports needed speed first, while border site selection needed greater accuracy. The quality of an index depends on the trade-off among speed, space and error.