Converting a prefix table into a Z-table on the word RAM #
The program overwrites its input table with the canonical representative word, scanning left to
right. At position i, an entry k with 0 < k ≤ i copies the representative at position
k - 1. Every other entry assigns the fresh symbol i. This pointed read uses address k
directly because the representative word starts at address one. Clearing the scan's registers
restores the full initial-state layout for the certified Z-algorithm.
The program takes at most 50 * n + 19 instructions, including halt, at any width fitting
2 * n + 1 and the input entries. Its length-prefixed Z-table starts at address n + 1.
For an actual KMP prefix table, fromPrefix_computePrefix identifies the output with the Z-table
of the original word.
Convert the input prefix table in place to a representative word and run the Z-algorithm.
Prefix-table to Z-table conversion with the result pointer returned in Reg.out.
On an array of n prefix lengths, the program writes the length-prefixed Z-table at
address n + 1, leaving the representative word in the input block. The bound charges both
the in-place conversion and the Z-algorithm.
The uniform 16-register word-RAM program converts a length-prefixed prefix table of size
n within 50 * n + 19 instructions, including halt, when the width fits 2 * n + 1
and the input words.
On the KMP table of any word, the program outputs its Z-table. Every proper border length fits when the final output address fits, regardless of the word's alphabet.