Skip to content

Bug: In an edge case, GenDiff will misidentify a Remove/Add as an Update #10

@nesevis

Description

@nesevis

The edge case occurs while diffing a data source against a reversed version of itself.

Example: A list of 100 items with indices 0..99.

Link to code

if (i > 0 && j > 0 && match(x[i - 1], y[j - 1])) {
	GenDiff(c, x, y, i - 1, j - 1, match);
	Actions.Add(new ListDiffAction<S, D>(ListDiffActionType.Update, x[i - 1], y[j - 1]));
}

This check will return true while comparing original[99] with new[0].

My fix is just adding a check to see whether the indices match as well:

if (i > 0 && j > 0 && sourceIdx == destIdx && match(x[i - 1], y[j - 1]))
	GenDiff(c, x, y, i - 1, j - 1, match);
	Actions.Add(new ListDiffAction<S, D>(ListDiffActionType.Update, x[i - 1], y[j - 1]));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions