Searching with a parent cursor and comparison path #
seek follows the ordinary binary-search decisions while retaining the immediate parent in
register two, including when the search reaches an empty child. Its ghost context records
ancestors and the inequalities that selected each child, for subsequent insertion proofs.
The program is read-only and uses no machine stack. This is an original implementation of
Frontier's functional search, with explicit pointer-machine instruction accounting.
Search from cursor zero for query data register zero, retaining the parent in pointer two. Pointer five is null scratch and data one is comparison scratch.
Every ancestor frame records the strict comparison that selected its focused child.
An unsuccessful search path selects a vacant parent slot. The concrete comparison with that parent's key chooses exactly the side recorded by the ghost context.
A search focus and its ancestor context, with the comparison decisions and register frame. The context is mathematical proof data, not storage used by the machine.
No record is modified or allocated.
Only comparison scratch data register one may change.
Only cursor, parent and null scratch pointers may change.
The cursor identifies the final focus.
The parent survives even when the focus is empty.
The original whole tree is recovered from the returned focus and context.
The focused subtree retains its complete heap representation.
All ancestor links and sibling subtrees retain their representation.
- path : SearchPath (x.data 0) cs
Each descent follows the query comparison at its ancestor.
- stop : match focus, ⋯, ⋯, ⋯, ⋯ with | BinaryTree.nil, cursor, reconstruction, rep, context => True | BinaryTree.node a left right, cursor, reconstruction, rep, context => a.data 0 = x.data 0
The focus is empty or its root key equals the query.
A nonnull focus agrees with the existing functional search.
Parent-preserving search uses at most seven instructions per visited node plus four for initialization and termination, including halt. It returns the entire comparison path; no ordering premise is needed for agreement with the functional search algorithm.