Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*_new.json
*_patch.json
*.csv
node_modules/
package-lock.json
29 changes: 20 additions & 9 deletions JSON-Diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ function generateArrayDiff(oldJson, newJson, unchanged, patches, path) {

// Use LCS
var tmpPatches = [];
var tmpPatchHashes = [];

if (oldJson.length === 0) {
patches.push({ op: "add", path: path, value: newJson});
} else {
// Use sortBack
tmpPatches = transformArray(oldJson, newJson, unchanged, tmpPatches, tmpPatchHashes, path);
// deleted unused parameters from the call
tmpPatches = transformArray(oldJson, newJson, unchanged, path);
for (var l = 0; l < tmpPatches.length; l++) {
patches.push(tmpPatches[l]);
}
Expand Down Expand Up @@ -146,7 +146,9 @@ function generateObjectDiff(oldJson, newJson, unchanged, patches, path) {
if (!oldJson.hasOwnProperty(newKey)) {
//Try to find the value in the unchanged area
// change JSON.stringify()
var pointer = unchangedArea.findValueInUnchanged(JSON.stringify(newVal), unchanged);

// pass the value here, apply JSON.stringify in the method
var pointer = unchangedArea.findValueInUnchanged(newVal, unchanged);
if (pointer) {
//COPY
patches.push({ op: "copy", path: path + "/" + patchPointString(newKey), from: pointer});
Expand Down Expand Up @@ -294,7 +296,8 @@ function findCopyInArray(element, m, array, arrUnchanged) {
return copyIndex;
}

function transformArray(oldJson, newJson, unchanged, patches, patchHashes, path, jsondiff) {
// deleted unused parameters
function transformArray(oldJson, newJson, unchanged, path) {
//When is the Array, stop to find leaf node
// (hash, value, index)
var x = hashObject.mapArray(hashObject.hash, oldJson, HASH_ID);
Expand All @@ -315,6 +318,7 @@ function transformArray(oldJson, newJson, unchanged, patches, patchHashes, path,

while (i < x_sorted.length) {
while( j < y_sorted.length) {

if(x_sorted[i] !== void 0) {

if (x_sorted[i].hash > y_sorted[j].hash) {
Expand All @@ -323,7 +327,11 @@ function transformArray(oldJson, newJson, unchanged, patches, patchHashes, path,

} else if (x_sorted[i].hash === y_sorted[j].hash) {
// Unchanged push
unchanged.push( path + '/' + y_sorted[j].index + "=" + JSON.stringify(x_sorted[i].hash));
//no point to insert if already there
var el = path + '/' + y_sorted[j].index + "=" + JSON.stringify(x_sorted[i].value);
if (unchanged.indexOf(el)<0)
unchanged.push(el);

arrPatch.push({op: "move", value: y_sorted[j].value, valueOld: x_sorted[i].value, from: x_sorted[i].index , index: y_sorted[j].index, hash: y_sorted[j].hash });
i++;
j++;
Expand All @@ -338,14 +346,15 @@ function transformArray(oldJson, newJson, unchanged, patches, patchHashes, path,
j++;
}

}
} //j

if (i < x_sorted.length) {
// Remove the rest elements of the x_sorted
arrPatch.push({op: "remove", index: x_sorted[i].index, value: x_sorted[i].value });
// for being consistent, added hash as well like for other operators
arrPatch.push({op: "remove", index: x_sorted[i].index, value: x_sorted[i].value, hash: x_sorted[i].hash });
i++;
}
}
} //i

//Get the patch to make all the elements are the same, but index is random
arrPatch = arrPatch.sort(compare);
Expand Down Expand Up @@ -462,6 +471,8 @@ function transformArray(oldJson, newJson, unchanged, patches, patchHashes, path,

}

/*
// no reason to do anything with arrPatch local variable at this point
arrPatch = arrPatch.map(function(obj) {
obj.path = path + '/' + obj.index;
delete obj.hash;
Expand All @@ -473,7 +484,7 @@ function transformArray(oldJson, newJson, unchanged, patches, patchHashes, path,

return obj;
});
*/

return arrtmp;

}
61 changes: 0 additions & 61 deletions dataset/Stackoverflow/Stackoverflow.csv

This file was deleted.

15 changes: 0 additions & 15 deletions dataset/Twitter/Twitter.csv

This file was deleted.

61 changes: 0 additions & 61 deletions dataset/Xignite/Xignite.csv

This file was deleted.

9 changes: 5 additions & 4 deletions dataset/generate_patch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var jsonpatch = require('fast-json-patch'),
jiff = require('jiff'),
rfc6902 = require('rfc6902'),
jdr = require('json-diff-rfc6902'),
jdr = require('../json-diff-rfc6902'),
json8 = require('json8-patch'),
fs = require('fs'),
now = require("performance-now");
Expand All @@ -18,7 +18,8 @@ for (var i = 0; i < data.length; i++) {
var root = "./" + data[i] + "/";
// Write title
var title = data[i]+',A0_DT,A0_PS,A1_DT,A1_PS,A2_DT,A2_PS,A3_DT,A3_PS,A4_DT,A4_PS,A5_DT,A5_PS' + '\n';
fs.writeFile(root + data[i] +'.csv', title, {flag: 'a'} );
//use synched to avoid fs warning
fs.writeFileSync(root + data[i] +'.csv', title, {flag: 'a'} );

for (var j = 1; j <= versionNum; j++) {

Expand Down Expand Up @@ -87,8 +88,8 @@ function generatePatch(root, data, f_old, f_new, version, algorithm) {
result = result + '\n';
}


fs.writeFile(root + data +'.csv', result, {flag: 'a'});
//use synched to avoid fs warning
fs.writeFileSync(root + data +'.csv', result, {flag: 'a'});

}

Expand Down
1 change: 0 additions & 1 deletion dataset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"dependencies": {
"fast-json-patch": "^0.5.7",
"jiff": "^0.7.3",
"json-diff-rfc6902": "^1.3.3",
"json8-patch": "^0.4.0",
"performance-now": "^0.2.0",
"rfc6902": "^1.2.1"
Expand Down
Loading