Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion genscripts/generate_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""

SCRIPTS_TEMPLATE = """
from typing import Set, Dict, Tuple
from typing import List, Set, Dict, Tuple
"""


Expand Down Expand Up @@ -92,6 +92,18 @@ def generate_script_data() -> None:

content = SCRIPTS_TEMPLATE
content += "RANGES: Dict[Tuple[int, int], str] = {}\n\n".format(ranges)

# Pre-compute sorted ranges for binary search - sorted by start value
sorted_ranges = sorted(
[(start, end, script) for (start, end), script in ranges.items()],
key=lambda x: x[0],
)
range_starts = [r[0] for r in sorted_ranges]

content += "SORTED_RANGES: List[Tuple[int, int, str]] = {!r}\n\n".format(
sorted_ranges
)
content += "RANGE_STARTS: List[int] = {!r}\n\n".format(range_starts)
content += "LATIN_CHARS: Set[int] = {} # fmt: skip \n\n".format(latin_chars)
content += "LATINIZABLE_CHARS: Set[int] = {} # fmt: skip \n\n".format(
latinizable_chars
Expand Down
Loading