Skip to content

Type Editor


Type Editor / @type-editor/changeset / compute-diff / computeDiff

Function: computeDiff()

ts
function computeDiff<T>(fragA, fragB, range, encoder?): Change<any>[];

Defined in: compute-diff.ts:24

Compute the difference between two fragments using Myers' diff algorithm.

This implementation optimizes by first scanning from both ends to eliminate unchanged content, then applies the Myers algorithm to the remaining content. For performance reasons, the diff computation is limited by MAX_DIFF_SIZE.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
fragAFragmentThe first fragment to compare.
fragBFragmentThe second fragment to compare.
rangeChangeThe change range to analyze.
encoderTokenEncoder<T>The encoder to use for tokenization (defaults to DefaultEncoder).

Returns

Change<any>[]

An array of Change objects representing the differences.