From dc2902dde000a49c4bd0996e1cac70ecc03bb5af Mon Sep 17 00:00:00 2001 From: David Greenspan Date: Tue, 3 Apr 2012 21:09:53 -0700 Subject: [PATCH] snapshots changes with Geoff (comments) --- packages/minimongo/diff.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/minimongo/diff.js b/packages/minimongo/diff.js index 9d89984ea2..b1c4c7d6ad 100644 --- a/packages/minimongo/diff.js +++ b/packages/minimongo/diff.js @@ -79,14 +79,17 @@ LocalCollection._diffQuery = function (old_results, new_results, observer, deepc // To determine which docs should be considered "moved" (and which // merely change position because of other docs moving) we run // a "longest common subsequence" (LCS) algorithm. The LCS of the - // doc IDs and the new doc IDs gives the docs that should NOT be + // old doc IDs and the new doc IDs gives the docs that should NOT be // considered moved. // // Overall, this diff implementation is asymptotically good, but could // be optimized to streamline execution and use less memory (e.g. not // have to build data structures with an entry for every doc). - + // Asymptotically: O(N k) where k is number of ops, or potentially + // O(N log N) if inner loop of LCS were made to be binary search. + + //////// LCS (longest common sequence, with respect to _id) // (see Wikipedia article on Longest Increasing Subsequence, // where the LIS is taken of the sequence of old indices of the @@ -139,7 +142,7 @@ LocalCollection._diffQuery = function (old_results, new_results, observer, deepc idx = ptrs[idx]; } - //////// Main Algorithm + //////// Main Diff Algorithm var old_idx = 0; var new_idx = 0;