Skip to main content

serialize_validate

Function serialize_validate 

Source
pub fn serialize_validate(tree: &SerializedTree) -> Result<(), String>
Expand description

Validate a tree against the walk’s invariants before publishing.

Every node count must sit in [1, MLFQ_TREE_MAX_NODES]. Every node must be reachable from the root. Every leaf (right == 0) is unconstrained beyond that. Every internal node must split on a feature id below the nine populated slots, both children must be in-bounds, and both must follow the parent in the BFS order (parents before children), which the store layout relies on.

The walk descends at most MLFQ_TREE_MAX_DEPTH edges and then, depth exhausted, returns the last reachable node’s left only when that node is a leaf. A node deeper than MLFQ_TREE_MAX_DEPTH is therefore unreachable, and an internal node at depth MLFQ_TREE_MAX_DEPTH would only ever be read through the exhaustion fallback (predicting 0). Both shapes are rejected, so a published tree’s every reachable prediction is a real leaf.