Documentation

CslibFrontier.Algorithms.WordRAM.ZFunction.ToPrefix

Converting Z-values to the KMP prefix table on the Word-RAM #

The input is the length-prefixed Z-table alone. At prefix length t, the earliest start j ≥ 1 whose Z-box reaches t gives the longest proper border, of length t - j. A box that falls short can be discarded for every later prefix. Each iteration either discards a start or writes one answer. Both pointers move only to the right.

toPrefixProgram_computesListInTime counts the reads, writes, pointer updates, tests and final halt on the standard Word-RAM. For n input words the output occupies addresses n+1 through 2n+1, including its length header, and words must fit these addresses.

Convert the length-prefixed Z-table at address zero into the length-prefixed KMP table immediately following it.

From the Z-table alone, compute the prefix-table conversion in at most 20n + 9 standard Word-RAM instructions, including the final halt, at any width fitting 2n + 1. On realizable input tables the result is KMP's prefix table by zToPrefix_zArray.

On the Z-table of any word, the program outputs that word's KMP table. Fitting the last output address suffices for the width, since each input Z-value is at most the word length.