The table will be {a :(1,1), b :(1,1), ...} because each line appears in both files exactly once.
do {
c = a;
d = b;
// first pass a=0, b=0
// the lines aren't equal, they're "1" and "a" so we pass this case.
if (one[a] === two[b]) {
equality();
} else {
//one[0] is "1", matching 1:(1,1)
//two[0] is "a", matching a:(1,1)
if (table[one[a]].two < 1 && table[two[b]].one < 1) {
//can't get here
replaceUniques();
} else if (table[one[a]].two < 1 && one[a + 1] !== two[b + 2]) {
// 1:(1,1) cdr not less than 1, so this is out
deletion();
} else if (table[two[b]].one < 1 && one[a + 2] !== two[b + 1]) {
// a:(1,1) car not less than 1, so this is out
insertion();
} else if (table[one[a]].one - table[one[a]].two === 1 && one[a + 1] !== two[b + 2]) {
// 0 === one[a+1] !== two[b+2]
// === "2" !== "c"
// === true
deletionStatic();
} else if (table[two[b]].two - table[two[b]].one === 1 && one[a + 2] !== two[b + 1]) {
// 0 === one[a+2] !== two[b+1]
// === "3" !== "b"
// === true
insertionStatic();
} else {
// so we're stuck replacing.
replacement();
}
}
a += 1;
b += 1;
} while (a < lena && b < lenb);
it's very pretty, it just seems like it's not not doing enough lookahead to find those long distance relationships.(although i didn't run it, i could have screwed up my interpretation)
in my limited experience, diff is very hard.
edit
fixed a couple typos in the comments.
yeah, three deletes and three inserts showing at least 3 lines of equality is preferable. ideally it'd show a single edit, move of 3 lines, but that's really hard to do.