Reconnecting a rotated subtree #
Cursor zero holds the promoted node and register six holds the former root. The program reads the promoted node's parent link. At the overall root it updates root register one; otherwise it replaces the parent's link to the former root. This is a local attachment contract; whole-tree composition additionally needs the rotation's representation and separation invariants.
Reconnect the rotated subtree at cursor zero, replacing the former root in register six. Scratch registers two, three and five may change.
Reconnecting the overall root takes five instructions, leaves the heap and scalar registers unchanged, and installs the cursor in root register one.
Reconnecting below a parent takes seven instructions. Exactly one parent child link changes from the saved former root to the cursor; all other records and fields are preserved. The caller supplies the parent's old child link, not the resulting heap.