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.query,NeighborProgram.cut,NeighborProgram.count,NeighborProgram.base,NeighborProgram.stride,NeighborProgram.one,NeighborProgram.leftIndex,NeighborProgram.rightIndex,NeighborProgram.excess,NeighborProgram.address,NeighborProgram.leftKey,NeighborProgram.rightKey,NeighborProgram.leftXor,NeighborProgram.rightXor,NeighborProgram.chosen,NeighborProgram.divergence,NeighborProgram.index: register assignments for loading and comparing sketch neighbors.NeighborProgram.left,NeighborProgram.right: clamped predecessor and successor indices.NeighborProgram.code: load two full keys and choose the smaller exclusive or.NeighborProgram.loaded,NeighborProgram.result: register and memory states after loading both keys and after selecting the neighbor.
Main results #
NeighborProgram.exec: checked execution in at most eighteen instructions.
References #
Query word, preserved.
Inclusive sketch cut, preserved.
Nonzero node occupancy, preserved.
Address of the first full key, preserved.
Distance between full keys, preserved.
Constant one.
Clamped predecessor index.
Clamped successor index.
Clamping scratch.
Memory address scratch.
First candidate key.
Second candidate key.
First candidate's exclusive or with the query.
Second candidate's exclusive or with the query.
Selected key.
Selected key's exclusive or with the query.
Selected array index.
Clamped predecessor position.
Clamped successor position, expressed using two saturating subtractions.
Thirteen instructions load the candidates. Selection adds four or five instructions, including control flow, and prefers the left candidate when exclusive-or values tie.
State after loading, before the one comparison selecting a candidate.
Final state, choosing the smaller full-word exclusive or.
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.