MCPcopy
hub / github.com/loggerhead/json4u / histogramDiff

Function histogramDiff

src/lib/compare/histogram.ts:6–18  ·  view source on GitHub ↗
(a: string, b: string)

Source from the content-addressed store, hash-verified

4// stolen from https://github.com/octavore/delta/blob/master/lib/histogram.go
5// HistogramDiff uses the histogram diff algorithm to generate a line-based diff between two strings
6export function histogramDiff(a: string, b: string): DiffPair[] {
7 if (a.length + b.length === 0) {
8 return [];
9 } else if (a.length === 0) {
10 return [{ right: newDiff(0, b.length, "ins") }];
11 } else if (b.length === 0) {
12 return [{ left: newDiff(0, a.length, "del") }];
13 }
14
15 const aa = a.split("\n");
16 const bb = b.split("\n");
17 return new HistogramDiffer(aa, bb).solve();
18}
19
20// Histogram of lines.
21class Histogram {

Callers 1

compareTextFunction · 0.90

Calls 2

newDiffFunction · 0.90
solveMethod · 0.80

Tested by

no test coverage detected