Loading and selecting sketch neighbors #
An inclusive sketch cut has at most two neighboring full keys. Clamp the two indices to a nonempty array, load both keys, and compare their exclusive or with the query. Clamping allows the same bounded program to handle cuts at either end of the array.
Main definitions #
NeighborProgram.code: load two full keys and choose the smaller exclusive or.
Main results #
NeighborProgram.exec: checked execution in at most eighteen instructions.
References #
Query word, preserved.
Instances For
Inclusive sketch cut, preserved.
Instances For
Nonzero node occupancy, preserved.
Instances For
Address of the first full key, preserved.
Instances For
Distance between full keys, preserved.
Instances For
Constant one.
Instances For
Clamped predecessor index.
Instances For
Clamped successor index.
Instances For
Clamping scratch.
Instances For
Memory address scratch.
Instances For
First candidate key.
Instances For
Second candidate key.
Instances For
First candidate's exclusive or with the query.
Instances For
Second candidate's exclusive or with the query.
Instances For
Selected key.
Instances For
Selected key's exclusive or with the query.
Instances For
Selected array index.
Instances For
Clamped predecessor position.
Instances For
Clamped successor position, expressed using two saturating subtractions.
Instances For
The clamped comparison chooses a valid neighbor of minimum score among all neighbors of the cut. At either end the repeated candidate causes no exception.
Thirteen instructions load the candidates. Selection adds four or five instructions, including control flow, and prefers the left candidate when exclusive-or values tie.
Instances For
State after loading, before the one comparison selecting a candidate.
Instances For
Final state, choosing the smaller full-word exclusive or.
Instances For
The returned key, exclusive-or value, and index describe the same selected array entry.
With an actual sketch cut and an encoded full-key array, the output identifies a sketch neighbor with minimum exclusive-or value among the neighbors. No full-key scan supplies the answer. The statement is separate from the checked execution and can be composed with it.
Loading two clamped neighbors and selecting one takes at most eighteen actual checked instructions. The address premise covers the last array key; every accessed address and intermediate product lies below it. The query, cut, occupancy, base, stride, and memory are preserved. Constant preparation and the sketch cut itself are separate.