Skip to content

Fix binary search in find_dict_prefix() - #356

Merged
dstelzer merged 3 commits into
Dialog-IF:mainfrom
sehugg:find-dict-prefix
Sep 16, 2026
Merged

dstelzer merged 3 commits into
Dialog-IF:mainfrom
sehugg:find-dict-prefix

Conversation

@sehugg

@sehugg sehugg commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

The find_dict_prefix() function searches for dictionary words so it can replace them as escapes in the WRIT chunk. There was an off-by-one bug in the binary search code that made it miss most of the matches. It also made a wrong assumption about the string ordering, say we have this dictionary:

cloak
cloakroom

If we try to find a prefix for "cloaks" we should find "cloak" but the insertion point for "cloaks" is to the right of "cloakroom" so it'll never go there. The solution is to repeat the binary search on prefixes of a given length, starting with the longest dictionary word length.

These two fixes reduce the size of the example stories by 2 or 3 percent.

@dstelzer
dstelzer merged commit 3fbdbef into Dialog-IF:main Sep 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants