Mean similarity between two equal-length line arrays.
(a: string[], b: string[])
| 69 | |
| 70 | /** Mean similarity between two equal-length line arrays. */ |
| 71 | function blockSim(a: string[], b: string[]): number { |
| 72 | const n = Math.min(a.length, b.length); |
| 73 | if (n === 0) return 0; |
| 74 | let sum = 0; |
| 75 | for (let i = 0; i < n; i++) sum += lineSim(a[i]!, b[i]!); |
| 76 | // Penalize length mismatch. |
| 77 | const lenPenalty = Math.min(a.length, b.length) / Math.max(a.length, b.length); |
| 78 | return (sum / n) * lenPenalty; |
| 79 | } |
| 80 | |
| 81 | /** Convert a [startLine,endLine) line range to char offsets in `content`. */ |
| 82 | function lineRangeToOffsets(lineStarts: number[], content: string, startLine: number, endLine: number): { start: number; end: number } { |