execute<E> method

  1. @override
ListDiffs<E> execute<E>(
  1. ListDiffArguments<E> args
)
override

Implementation

@override
ListDiffs<E> execute<E>(final ListDiffArguments<E> args) {
  final original = args.original;
  final replacement = args.replacement;

  final ppResult = preprocessListDiff<E>(args);
  if (ppResult != null) return ppResult;

  final previousRow = Row<E>(args);
  previousRow.seed(replacement);
  final currentRow = Row<E>(args);

  // row in matrix
  var indexInOld = 0;
  original.forEach((oldItem) {
    // reset current row
    currentRow.reset(
      count: previousRow.slots.length,
      indexInOld: indexInOld,
      oldItem: oldItem,
    );

    // column in matrix
    var indexInNew = 0;
    replacement.forEach((newItem) {
      if (args.compare(isIdentityOnly, oldItem, newItem)) {
        currentRow.update(indexInNew: indexInNew, previousRow: previousRow);
      } else {
        currentRow.updateWithMin(
            previousRow: previousRow,
            indexInNew: indexInNew,
            newItem: newItem,
            indexInOld: indexInOld,
            oldItem: oldItem);
      }
      indexInNew++;
    });

    // set previousRow
    previousRow.slots = [...currentRow.slots];
    indexInOld++;
  });

  final changes = currentRow.lastSlot();
  return changes;
}