Skip to content

Commit

Permalink
Added more tests, bug fixes for diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Amor Kvalheim committed Jul 16, 2010
1 parent 24c0dfd commit 30075be
Show file tree
Hide file tree
Showing 2 changed files with 420 additions and 110 deletions.
21 changes: 11 additions & 10 deletions lib/diff/diff.js
Expand Up @@ -383,23 +383,29 @@ Difference.LCS.traverse_balanced = function(seq1, seq2, callbacks, block) {
// Ensure that we have at least a default callback object
callbacks = callbacks != null ? callbacks : new Difference.LCS.BalancedCallbacks();
// Fetch the matches from the __lcs algorithm
var matches = Difference.LCS.__lcs(seq1, seq2);

var matches = Difference.LCS.__lcs(seq1, seq2);
var a_size = seq1.length;
var b_size = seq2.length;
var ai = 0, bj = 0, mb = 0;
var ai = 0, bj = 0;
var mb = 0;
var ma = -1;
var string = seq1.constructor == String;
var ax = null, bx = null, event = null;
var execute = true;

// Process all the lines in the match vector.
while(true) {
// Find next match indices +ma+ and +mb+
while(true) {
while(execute) {
ma = ma + 1;
// sys.puts(" -- " + !(ma < matches.size && matches[ma] == null))
if(!(ma < matches.length && matches[ma] == null)) break;
// execute = !(ma < matches.length && matches[ma] == null);
}

// sys.puts("ma: " + ma)
// sys.puts("====================================== " + (ma < matches.size && matches[ma] == null))

if(ma >= matches.length) break; // end of matches
mb = matches[ma];

Expand Down Expand Up @@ -593,12 +599,7 @@ Difference.LCS.__lcs = function(a, b) {
if(kk != null) links[kk] = [(kk > 0) ? links[kk - 1] : null, ii, jj];
});
}

// Preinitialize the vector array so we get the nulls at the right points
for(var i = 0; i < (a_finish - a_start - 1); i++) {
vector[i] = null;
}


// Build the vector
if(thresh.length > 0) {
var link = links[thresh.length - 1];
Expand Down

0 comments on commit 30075be

Please sign in to comment.