Skip to content

Glyph to word indexing#3

Open
boisvert42 wants to merge 2 commits intorf-:mainfrom
boisvert42:glyph-to-word-indexing
Open

Glyph to word indexing#3
boisvert42 wants to merge 2 commits intorf-:mainfrom
boisvert42:glyph-to-word-indexing

Conversation

@boisvert42
Copy link
Copy Markdown

@boisvert42 boisvert42 commented Mar 23, 2026

  1. The Bottleneck: O(N) Option Scanning
    In the original establish_arc_consistency, whenever a glyph became "depleted" (count reached 0) in a cell, the algorithm would:
  2. Find the crossing slot.
  3. Iterate through every single word (other_slot_options) in that crossing slot.
  4. Check if that word's letter at the crossing point was the depleted glyph.

If a slot has 10,000 potential words, it performs 10,000 checks every time a letter is eliminated. In a 15x15 grid, this happens thousands of times per second.

  1. The Solution: Glyph-to-Word Indexing
    We can introduce a new index, slot_options_by_glyph, inside GridConfig. It is a 4D structure: [slot_id][cell_index][glyph_id] -> Vec.
  • Pre-computation: This index is populated once when the GridConfig is created. It maps every possible letter in every cell to the specific subset of words that contain that letter.
  • Constant-Time Trigger: In establish_arc_consistency, we now track depleted_glyphs_by_cell. When a glyph count hits zero, we don't scan anything. We simply look up the crossing slot and the crossing cell in our index.
  • Targeted Elimination: The index gives us exactly the list of WordIds that are now invalid. We only iterate over the words that must be removed.

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.

1 participant