Home Manual Reference Source

Function

Static Public Summary
public

build(p: ArrayLike, pi: number, pj: number, t: number[], ti: number)

Computes the failure function for input string.

Static Public

public build(p: ArrayLike, pi: number, pj: number, t: number[], ti: number) source

Computes the failure function for input string.

This is the "next[j]" table found in "Fast pattern matching in strings" by Knuth, Morris, and Pratt, although here indices are 0-based hence all indices and inputs are one less than in that paper.

NOTE The main loop is somewhat unrolled for faster execution. This was not benchmarked.

Params:

NameTypeAttributeDescription
p ArrayLike
pi number
pj number
t number[]
ti number