treestore-cm
The groupant beside tools/treestore/src/cm.rs in the Mova repository: what the code computes, what it never does, how to go back from its outputs, its invariants, cost and checks.
Facts
Implementation material. A Mova code model describes this code at one source revision: partial models, finite checks and their stated scope. It is not a reviewed general exposition, and its labels are shown as written, never raised.
Components
| component | label | where |
|---|---|---|
| Approximant | partial | Approximant |
| Ast | partial | syntax.json |
| Composition | partial | Composition |
| Cost | symbolic source derived | Invariant |
| Descriptant | present | Descriptant |
| Invariant | partial | Invariant |
| Tests | executed bounded checks | Tests |
Obernants
The typed relations around the forward model: the behaviour complement (what the code never does), the reverse reconstruction (every input compatible with an output) and specialised views.
| relation | type | label | where |
|---|---|---|---|
| Behavior complement | behavior complement | partial source derived model | Behavior complement |
| Reverse reconstruction | reverse reconstruction | partial source derived model | Reverse reconstruction |
Model text
Descriptant
A context-model coder for symbol streams: PPM with orders 2, 1, 0 (Cleary & Witten 1984; escape method C, Moffat 1990), a raw fallback for unseen symbols, a 32-bit range coder with carry (Martin 1979; LZMA's byte layout), and a primed model learned from the sample (the counterpart of a trained zstd dictionary). Primed contexts are copied on first update only. Epoch 2026-11-06.
Approximant
Cost per symbol โ โlog2 P(s | two before) bits plus escapes. Measured 2026-11-06, shard 00050: store 12.92 MB with zstd only โ 11.98 MB with the coder chosen per stream (shape 2.38 โ 2.06 MB, frames 2.54 โ 2.04 MB, lemma 0.56 โ 0.49 MB); decode about 2ร slower (56 โ 26โ32 MB/s of JSON).
Invariant
unpack(pack(raw, P), P) = raw for every canonical varint stream and every primed model P (encoder and decoder make the same model updates in the same order; HashMap only for lookup, so iteration order never matters). Totals stay below 2^16 (halving, then dropping the rarest), so r = range/total โฅ 2^8. Cost O(symbols ยท scanned context entries).
Composition
store::compress tries it on the streams in CM_STREAMS and keeps it (method 3) when smaller than zstd; the written frame is decoded back before it is accepted.
Behavior complement
Not used for text (env, md, lit) or the near-uniform confidences (conf); no exclusion, no SEE, no mixing of
orders; a damaged frame is not detected here (the article hash in store.rs does that).
Reverse reconstruction
Exact inverse given the same primed model and symbol count; without the model the bytes do not determine the symbols.
Tests
cm::tests::round_trip_and_gain (structured stream โฅ 3ร smaller than its varints, primed and unprimed round trips,
extreme values; negative controls: a damaged stream does not give the same bytes, non-varint input is refused).
Provenance
This page in Markdown โ https://md.groupants.elamur.ai/free/en/mova/tools/treestore/src/cm.rs.groupant/