zAlgorithm
Returns a usize[] where each position stores the length of the longest prefix of the input that starts at that position. The first value is always zero.
tyrus
import { zAlgorithm } from "tyrus:algorithm";
const values: usize[] = zAlgorithm("aabcaab");
print(values[1], values[4]); // 1 3Study result
tyrus
interface ZAlgorithmInfo {
text: string;
zTable: usize[];
comparisonCount: usize;
windowExtensionCount: usize;
}tyrus
import { ZAlgorithmInfo, zAlgorithmInfo } from "tyrus:algorithm";
const info: ZAlgorithmInfo = zAlgorithmInfo("aabcaab");
print(info.text); // aabcaab
print(info.zTable); // [0, 1, 0, 0, 3, 1, 0]
print(info.comparisonCount); // 9
print(info.windowExtensionCount); // 4The algorithm runs in O(n) time and uses O(n) space for the result.
