( a: ReadonlyArray<A>, b: ReadonlyArray<A>, equals: (i: number, j: number) => boolean, maxEdits?: number )
| 765 | } |
| 766 | |
| 767 | const editScript = <A>( |
| 768 | a: ReadonlyArray<A>, |
| 769 | b: ReadonlyArray<A>, |
| 770 | equals: (i: number, j: number) => boolean, |
| 771 | maxEdits?: number |
| 772 | ): Array<Edit<A>> => { |
| 773 | const blocks = matchingBlocks(a.length, b.length, equals, maxEdits) |
| 774 | // A final empty block flushes the trailing changes |
| 775 | blocks.push({ a: a.length, b: b.length, length: 0 }) |
| 776 | const out: Array<Edit<A>> = [] |
| 777 | let i = 0 |
| 778 | let j = 0 |
| 779 | for (const block of blocks) { |
| 780 | if (block.a > i) out.push({ _tag: "Delete", items: a.slice(i, block.a) }) |
| 781 | if (block.b > j) out.push({ _tag: "Insert", items: b.slice(j, block.b) }) |
| 782 | if (block.length > 0) out.push({ _tag: "Equal", items: a.slice(block.a, block.a + block.length) }) |
| 783 | i = block.a + block.length |
| 784 | j = block.b + block.length |
| 785 | } |
| 786 | return out |
| 787 | } |
| 788 | |
| 789 | /** |
| 790 | * Returns ordered, merged matching runs for sequences of lengths n and m, |
no test coverage detected