Skip to main content

Module insert

Module insert 

Source
Expand description

B+tree insert path with copy-on-write splits.

See docs/format.md § B+tree write semantics. Every node touched along the insert path is rewritten to a freshly-allocated page; the displaced pages enter the freelist only after the new root is staged in the pager’s WAL transaction buffer. The caller is responsible for calling Pager::commit to make the insert durable.

§Power-of-ten posture

  • Rule 1. The walk root → leaf uses an explicit heapless::Vec<_, MAX_BTREE_DEPTH> path stack. The bubble-up loop is a while let Some(...) over that stack — no recursion.
  • Rule 2. Every loop is bounded: by the path length (≤ MAX_BTREE_DEPTH), by key_count (a node’s slot count), or by LEAF_SLOT_CAP / INTERNAL_SLOT_CAP.
  • Rule 5. validate_node runs on every encoded node behind a debug_assert!; release builds surface invariant breaks as Error::BTreeInvariantViolated.