// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

export const DEFAULT_CHUNK_SIZE = 16_640;
export const DEFAULT_BUFFER_SIZE = 32 * 1024;

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

// denoCacheMetadata={"headers":{"cache-control":"public, max-age=31536000, immutable","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","set-cookie":"__cf_bm=UexlG5vUZAn.gQW8lyBLiEqq7KmE4ehmD1rZ88r0k2M-1785241875.2699535-1.0.1.1-JZ85qDtQLMGVDzWeUbtYb1qP44yP1xeuJZ3_pU6bVJ9fvuL0QI3WUA9THu3pxZPwPp5G10N5iDDYBcekdRL_oqcuAqaYYQrjOkBIgzx2516jzLGgWFfL2NWCd_ZaOKX.; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","content-type":"text/typescript","x-robots-tag":"noindex","age":"1642490","server":"cloudflare","alt-svc":"h3=\":443\"; ma=86400","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=xqel69TEZbJt9GzUJlEpOq%2FvoRn4pL1R4s0ANg7tGLrJQvOi3%2BkVfeRsK7TZvUwRYM3nWcO3qmOQz7wZORem5OSilVFf9wWgCFNwj4jiZJ6SlqHNMbVn6KY%3D\"}]}","access-control-expose-headers":"*","vary":"Origin","x-jsr-backend":"modules","date":"Tue, 28 Jul 2026 12:31:15 GMT","access-control-allow-origin":"*","cross-origin-resource-policy":"cross-origin","cf-ray":"a223e6586c587db6-LAX","cf-cache-status":"HIT","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","content-length":"698","x-content-type-options":"nosniff","etag":"\"4a185a1a4487cd149bf1b88ff570bd74\"","accept-ranges":"bytes"},"url":"https://jsr.io/@std/streams/0.224.5/_common.ts","time":1785241875}