1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//! Rat enumeration: depth-first walk over a cyclotomic ring's
//! unit-direction graph that finds every simple closed polygon
//! (`Rat`) up to a chosen perimeter.
//!
//! The enumeration is the engine behind the `rat_enum` binary; this
//! module exposes it as a library so the binary stays thin and so
//! tests (correctness cross-validation, OEIS pinning) can drive the
//! same code paths from `#[cfg(test)]` without spawning subprocesses.
//!
//! # Optional optimizations
//!
//! All on top of the baseline DFS, all gated by [`prune::Prunes`]:
//!
//! - **Reachability prune** (the `--reachability-prune` flag): the
//! necessary condition "can the remaining unit-step budget still
//! cancel the current head displacement?", checked at the places of
//! the field. Two complementary halves, installed together:
//! - **modular** ([`prune::modular`], finite places): for a set of
//! small moduli `m`, precomputes the mod-`m` displacements
//! reachable by sums of `<= r` unit vectors and rejects any
//! candidate whose post-step residue isn't in the table for the
//! remaining-steps slot. ~10-376× on rings with non-trivial
//! mod-2/3/4/6 structure.
//! - **shadow-radius** ([`prune::shadow`], archimedean places): the
//! always-on baseline `within_radius` bounds the head in the
//! *physical* embedding (`|sigma_1(head)| <= remaining`); this
//! extends the identical bound to the non-physical conjugate
//! ("shadow") places the physical check cannot see. Since the
//! field norm is a nonzero integer, a head physically near the
//! origin necessarily has a large shadow.
//!
//! - **Closure-table prune** ([`prune::closure_table`], the
//! `--closure-table-prune` flag): pre-enumerates every simple open
//! snake up to length `L` and stores their (endpoint, facing)
//! "closure keys". When the DFS's remaining step budget is `<= L`,
//! rejects any candidate whose required suffix key isn't in the
//! table. Strictly stronger than any reachability projection (uses
//! exact lattice + facing info). Adds 2-5× on top.
//!
//! # Output modes
//!
//! Driven by the binary's `--mode` flag (see `Mode` in
//! `src/bin/rat_enum.rs`); the library exposes the underlying
//! functions independent of any CLI framing.
//!
//! - In-memory: [`enumerate_dispatch`] / [`run_rat_enum_seqs`]
//! return the full set as `Vec<Vec<i8>>`. Fine up to ~5 GB of
//! peak RSS.
//! - Streaming (memory-bounded, for large `n`): [`stream`] runs the
//! same DFS but routes closures through `FnMut(&[i8])` callbacks
//! into per-thread sort-buffer run files, then a k-way merge
//! stage produces a deduplicated sorted artifact plus a BLAKE3
//! certificate. See [`stream::stream_enum_dispatch`] and
//! [`stream::merge_runs`].
//!
//! See submodule docs for the specific contracts.
//!
//! # Correctness
//!
//! Every optimization has dedicated cross-validation tests against
//! the baseline DFS, plus an OEIS A316192 anchor through n=10. See
//! `opt_correctness_tests` in this module's `tests` submodule
//! (`#[cfg(test)]`).
use crateIsRing;
use crate;
use cratemake_ops;
use craterat_enum_with;
use cratesnapshot_prunes;
use craterat_enum_parallel;
use crateDfsStats;
use crate;
use crateSnake;
/// Output of a single-ring enumeration: the canonical sequences
/// (sorted by length), plus the DFS stats counters.
pub type EnumResult = ;
/// Generic ring-specific dispatcher: picks single-threaded vs parallel
/// based on `n_threads`, builds the canonical-ops pair, snapshots the
/// global prune state, and runs the enumeration. Returns the canonical
/// sequences (sorted by length) plus DFS stats.
/// Single- vs multi-threaded enumeration over a chosen boundary factory
/// -- the one place `n_threads` branches; the backend is entirely in `mk`.
/// Runtime-ring dispatcher: like [`enumerate_dispatch`] but takes a
/// `ring: u8` and selects the underlying type by match. Used by the
/// CLI which only knows the ring number at runtime.