Skip to content

Commit 7e7c649

Browse files
author
Codex Preflight
committed
Move correction references out of runtime
Keep test and benchmark-only structural helpers under tools/ so they no longer count against the installed review surface. Runtime search behavior is unchanged.\n\nValidation: Ruff, format check, mypy, focused correction tests, and the production-size budget test pass.
1 parent ccabfee commit 7e7c649

4 files changed

Lines changed: 55 additions & 45 deletions

File tree

‎src/codex32/indel.py‎

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ def _classes(unit: int, depth: int) -> tuple[_StructuralClass, ...]:
8888
_CHARACTER_CLASSES = _classes(1, 4)
8989
_GROUP_CLASSES = _classes(4, 2)
9090
_CLASSES = (_FIXED, *_CHARACTER_CLASSES, *_GROUP_CLASSES)
91-
# Compatibility for older offline tools; public search uses the full class set.
92-
_REDUCED_CLASSES = tuple(shape for shape in _CLASSES if shape.unit == 4 or shape.distance <= 3)
9391

9492

9593
def _group_boundary(immutable_length: int) -> int:
@@ -161,44 +159,6 @@ def _alignment_counts(
161159
return counts
162160

163161

164-
def _alignment_count(
165-
shape: _StructuralClass,
166-
observed_length: int,
167-
target_length: int,
168-
immutable_length: int,
169-
) -> int:
170-
return sum(_alignment_counts(shape, "q" * observed_length, target_length, immutable_length).values())
171-
172-
173-
def _reductions(
174-
values: tuple[int, ...],
175-
characters: str,
176-
count: int,
177-
offset: int,
178-
) -> Iterator[tuple[tuple[int, ...], tuple[tuple[int, str], ...]]]:
179-
for deleted in combinations(range(len(values)), count):
180-
removed = frozenset(deleted)
181-
kept = tuple(index for index in range(len(values)) if index not in removed)
182-
retained = tuple(values[index] for index in kept)
183-
position = 0
184-
for kept_index in kept:
185-
while values[position] != values[kept_index]:
186-
position += 1
187-
if position != kept_index:
188-
break
189-
position += 1
190-
else:
191-
edits = tuple((offset + index, characters[index]) for index in deleted)
192-
yield retained, edits
193-
194-
195-
def _variants(
196-
text: str, target: int, shape: _StructuralClass, immutable: int, prefix_length: int = 3
197-
) -> Iterator[_Variant]:
198-
for view in _views(text, target, shape, immutable, prefix_length):
199-
yield _view_variant(view, text, prefix_length)
200-
201-
202162
def _views(text: str, target: int, shape: _StructuralClass, immutable: int, base: int) -> Iterator[_View]:
203163
source = tuple(CHARSET.find(char.lower()) for char in text[base:])
204164
initial = _View(source, ((0, len(source)),), len(source))

‎tests/test_correction_indel.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,19 @@
1919
_CLASSES,
2020
_FIXED,
2121
_GROUP_CLASSES,
22-
_REDUCED_CLASSES,
23-
_alignment_count,
2422
_alignment_counts,
2523
_capacities,
2624
_frontier,
2725
_keep,
2826
_prepare,
29-
_reductions,
3027
_required_header_substitutions,
3128
_search_many,
3229
_search_target,
3330
)
3431
from codex32.profiles.ms32 import TEXT_LENGTHS
3532
from tools._wallet_reference import fingerprint_seed
3633
from tools.correction_capture import cross_length_classes
34+
from tools.correction_reference import _REDUCED_CLASSES, _alignment_count, _reductions
3735

3836
SOURCE = VECTOR_1["secret_s"]
3937
CONTEXT = CorrectionContext(Profile.MS, expected_length=len(SOURCE))

‎tools/correction_benchmark.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
from codex32.correction import CorrectionContext
1616
from codex32.indel import (
1717
_CHARACTER_CLASSES,
18-
_alignment_count,
1918
_required_header_substitutions,
2019
_search_many,
21-
_variants,
2220
)
2321
from codex32.profiles import Profile
2422
from codex32.profiles.ms32 import TEXT_LENGTHS
23+
from tools.correction_reference import _alignment_count, _variants
2524

2625
DELTAS = (-8, -4, -3, -2, -1, 0, 1, 2, 3, 4, 8)
2726
AUTOMATIC_48_COUNTS = (40, *range(44, 53), 56)

‎tools/correction_reference.py‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Reference-only structural helpers used by tests and correction benchmarks."""
2+
3+
from collections.abc import Iterator
4+
from itertools import combinations
5+
6+
from codex32.indel import (
7+
_CLASSES,
8+
_alignment_counts,
9+
_StructuralClass,
10+
_Variant,
11+
_view_variant,
12+
_views,
13+
)
14+
15+
_REDUCED_CLASSES = tuple(shape for shape in _CLASSES if shape.unit == 4 or shape.distance <= 3)
16+
17+
18+
def _alignment_count(
19+
shape: _StructuralClass,
20+
observed_length: int,
21+
target_length: int,
22+
immutable_length: int,
23+
) -> int:
24+
return sum(_alignment_counts(shape, "q" * observed_length, target_length, immutable_length).values())
25+
26+
27+
def _reductions(
28+
values: tuple[int, ...],
29+
characters: str,
30+
count: int,
31+
offset: int,
32+
) -> Iterator[tuple[tuple[int, ...], tuple[tuple[int, str], ...]]]:
33+
for deleted in combinations(range(len(values)), count):
34+
removed = frozenset(deleted)
35+
kept = tuple(index for index in range(len(values)) if index not in removed)
36+
retained = tuple(values[index] for index in kept)
37+
position = 0
38+
for kept_index in kept:
39+
while values[position] != values[kept_index]:
40+
position += 1
41+
if position != kept_index:
42+
break
43+
position += 1
44+
else:
45+
edits = tuple((offset + index, characters[index]) for index in deleted)
46+
yield retained, edits
47+
48+
49+
def _variants(
50+
text: str, target: int, shape: _StructuralClass, immutable: int, prefix_length: int = 3
51+
) -> Iterator[_Variant]:
52+
for view in _views(text, target, shape, immutable, prefix_length):
53+
yield _view_variant(view, text, prefix_length)

0 commit comments

Comments
 (0)