MCPcopy Create free account
hub / github.com/webpack/webpack-cli / myers32

Function myers32

packages/webpack-cli/src/webpack-cli.ts:287–328  ·  view source on GitHub ↗
(a: string, b: string, peq: Uint32Array)

Source from the content-addressed store, hash-verified

285let levenshteinPeq: Uint32Array | undefined;
286
287function myers32(a: string, b: string, peq: Uint32Array): number {
288 const n = a.length;
289 const m = b.length;
290 const lst = 1 << (n - 1);
291 let pv = -1;
292 let mv = 0;
293 let sc = n;
294 let i = n;
295
296 while (i--) {
297 peq[a.charCodeAt(i)] |= 1 << i;
298 }
299
300 for (i = 0; i < m; i++) {
301 let eq = peq[b.charCodeAt(i)];
302 const xv = eq | mv;
303
304 eq |= ((eq & pv) + pv) ^ pv;
305 mv |= ~(eq | pv);
306 pv &= eq;
307
308 if (mv & lst) {
309 sc++;
310 }
311
312 if (pv & lst) {
313 sc--;
314 }
315
316 mv = (mv << 1) | 1;
317 pv = (pv << 1) | ~(xv | mv);
318 mv &= xv;
319 }
320
321 i = n;
322
323 while (i--) {
324 peq[a.charCodeAt(i)] = 0;
325 }
326
327 return sc;
328}
329
330function myersX(longer: string, shorter: string, peq: Uint32Array): number {
331 const n = shorter.length;

Callers 1

distanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected