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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//! The one trait every tier instantiates (§6.1).
use ;
/// A decode from a stored code to alphabet elements.
///
/// `Bd` being a parameter of the trait is what makes the alphabet bound a
/// type-level fact the kernels can rely on without rechecking: a codec's table
/// is `&[Alphabet<E, Bd>]`, so its image is in the alphabet by construction and
/// there is nothing for a constructor to validate or reject (§6.2).
///
/// `E` is any element type. An integer codec's alphabet is a magnitude bound;
/// a float codec's is the codebook itself, declared as `Whole<E>` --- the
/// arena tier is the one instantiation of that, and no tier branches on the
/// difference.
/// A stored code stream, read as the index stream it already is.
///
/// The two widths a borrowed stream can be. The tabulated gather is
/// monomorphic in the code word --- one dispatch at the traversal's boundary,
/// never a per-code branch --- so the stream names its width in the type
/// rather than asking the gather to discover it. Both variants make the same
/// claim: `index_of(c) == (c as usize) & (CODE_SPACE - 1)` for every `c`,
/// which `CK-09` asserts of any codec that answers `Some`.
/// A codec whose code space can be enumerated.
///
/// [`Codec`] decodes *from* a code. That is the whole of what a
/// decode-then-multiply driver needs, and it is why a table indexed by code
/// cannot be written against [`Codec`] alone: such a table requires the *set* of
/// codes, and nothing in [`Codec`] hands it over. This trait is that set.
///
/// # Why this is separate from [`Codec`]
///
/// Not every codec should be tabulated. [`crate::Identity`] over `i32` has a
/// code space of `2^32`, and a trait that admitted it would invite a table
/// nobody can hold. Requiring this trait at the tabulated traversal's boundary
/// makes "this codec cannot be tabulated" a compile-time fact rather than a
/// runtime refusal.
///
/// # Laws
///
/// 1. `index_of(code_at(i)) == i` for every `i < CODE_SPACE`.
/// 2. `index_of` is total: every value of [`Codec::Code`] the codec can hold
/// lands strictly below `CODE_SPACE`. This is what makes the tabulated
/// traversal total --- no code can miss the table (`CT-07`).
///
/// Both are asserted by `CK-09`. Note what is *not* a law: `code_at` need not be
/// injective *on decodes*. Two indices may decode alike, in which case the table
/// carries a dead entry. That is not an error, it is a cost, and `CG-10` reports
/// the ratio.
///
/// # The enumeration is stateless
///
/// Both methods are associated functions rather than methods on `&self`, because
/// the enumeration is a property of the code *space* and not of any particular
/// table. A composing tier defers to its inner codec's enumeration without
/// holding an instance of it.
/// Which tier a codec is.
///
/// A label, never a dispatch key on the *answer*: two codecs with different
/// `TierId`s and equal decodes produce byte-identical output (`CK-05`), and
/// nothing in the library reads this to decide a value.
///
/// One derivation reads it at all --- [`crate::Addressing::of`], asking whether
/// the tier is one of the two with nothing between a code and an element --- and
/// what that decides is which *factorizations* exist, which `CD-13` already
/// holds to the same bytes either way.