Allocating and attaching a leaf #
insertLeaf fills a vacant child link of parent register two, or initializes root register one
when the parent is null. The side is fixed in the program. The original construction below
proves the exact heap update, fresh leaf representation and instruction count; ordering and
rebalancing belong to callers.
Attach cursor zero to the selected child of parent two, or set root one if parent is null. Register five is scratch.
Allocate a leaf with the supplied scalar fields and attach it at the selected vacant link. The null-parent case initializes root register one.
Filling a vacant child slot (or empty root) costs exactly extra + 9 instructions.
The new leaf has the complete supplied payload and parent link. The heap formula preserves every
old record except the selected parent's child link; all scalar registers and pointer registers
other than cursor, root and null scratch are unchanged. No ordering or balance is asserted.