---
title: "treestore-cm — Mova code model"
description: "Mova code model of tools/treestore/src/cm.rs: components with their labels, obernants and the model text."
url: "https://groupants.elamur.ai/free/en/mova/tools/treestore/src/cm.rs.groupant/"
---
Elamur: [Mova](https://md.mova.elamur.ai/free/en/) · [Dictionary](https://md.dictionary.elamur.ai/free/en/) · [Research](https://md.research.elamur.ai/free/en/) · **Groupants**

This page as HTML: <https://groupants.elamur.ai/free/en/mova/tools/treestore/src/cm.rs.groupant/>

# 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

- **kind:** groupant
- **status:** partial source bound model
- **source:** [`tools/treestore/src/cm.rs`](https://github.com/ElamurAI/mova-free/blob/main/tools/treestore/src/cm.rs)
- **repository folder:** [`tools/treestore/src/cm.rs.groupant`](https://github.com/ElamurAI/mova-free/tree/main/tools/treestore/src/cm.rs.groupant)

> **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](#approximant) |
| **Ast** | partial | `syntax.json` |
| **Composition** | partial | [Composition](#composition) |
| **Cost** | symbolic source derived | [Invariant](#invariant) |
| **Descriptant** | present | [Descriptant](#descriptant) |
| **Invariant** | partial | [Invariant](#invariant) |
| **Tests** | executed bounded checks | [Tests](#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](#behavior-complement) |
| Reverse reconstruction | reverse reconstruction | partial source derived model | [Reverse reconstruction](#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

- **source SHA-256:** `2f977e78d4d90fb7…`
- **repository commit:** `f55191f0d47f`
