function createLPS(
  pat,
) {
  const lps = new Uint8Array(pat.length);
  lps[0] = 0;
  let prefixEnd = 0;
  let i = 1;
  while (i < lps.length) {
    if (pat[i] == pat[prefixEnd]) {
      prefixEnd++;
      lps[i] = prefixEnd;
      i++;
    } else if (prefixEnd === 0) {
      lps[i] = 0;
      i++;
    } else {
      prefixEnd = pat[prefixEnd - 1];
    }
  }
  return lps;
}
/** Generate longest proper prefix which is also suffix array. */
Generate longest proper prefix which is also suffix array.
Generate longest proper prefix which is also suffix array .
function createLPS(
  pat,
) {
  const lps = new Uint8Array(pat.length);
  lps[0] = 0;
  let prefixEnd = 0;
  let i = 1;
  while (i < lps.length) {
    if (pat[i] == pat[prefixEnd]) {
      prefixEnd++;
      lps[i] = prefixEnd;
      i++;
    } else if (prefixEnd === 0) {
      lps[i] = 0;
      i++;
    } else {
      prefixEnd = pat[prefixEnd - 1];
    }
  }
  return lps;
}
function createLPS ( pat , ) { const lps = new Uint8Array ( pat . length ) ; lps [ 0 ] = 0 ; let prefixEnd = 0 ; let i = 1 ; while ( i < lps . length ) { if ( pat [ i ] == pat [ prefixEnd ] ) { prefixEnd ++ ; lps [ i ] = prefixEnd ; i ++ ; } else if ( prefixEnd === 0 ) { lps [ i ] = 0 ; i ++ ; } else { prefixEnd = pat [ prefixEnd - 1 ] ; } } return lps ; }
Generate longest proper prefix which is also suffix array.
Generate longest proper prefix which is also suffix array .