Repository navigation
index: derive rune offset sample at a corpus end on a sample boundary - #1299
Merged
Merged
Conversation
The builder writes a rune offset sample only when it reaches the start of a rune, so when a shard's content or filename corpus ends exactly on a multiple of runeOffsetFrequency runes there is no sample for the end. The lookup then extrapolated from the previous correction as if the trailing runes were ASCII, so findOffset at the end of the last file returned a wrong byte offset in non-ASCII shards. Derive the missing sample when loading the shard, since the corpus end in runes and bytes is already known there. This fixes existing shards without changing the on-disk format, and costs at most one extra correction per map. Found while reviewing #1294. Amp-Thread-ID: https://ampcode.com/threads/T-78959086-d0cc-476e-b607-38862deb5e09 Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The builder writes a rune offset sample only when it reaches the start of a rune, so when a shard's content (or filename) corpus ends exactly on a multiple of 100 runes, nothing is written for the end.
runeOffsetMap.lookupthen extrapolates from the previous correction as if the trailing runes were ASCII, sofindOffsetat the end of the last file returns a wrong byte offset in non-ASCII shards (e.g. 294 instead of 394 for a 197-runeéfile).The fix is in the reader:
makeRuneOffsetMapnow takes the corpus end in runes and bytes, whichread.goalready has, and adds the missing correction. That fixes existing shards without a format change and costs at most one extra correction per map. A sample written by some future builder at the end is used as is. Search results weren't affected in practice, becausefindOffsetis only called for match starts, which come before EOF. A search hit ending at EOF already returns correct offsets on main.Found while reviewing #1294. This is independent of it and merges cleanly with it.