Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array gaps not handled efficently #32

Open
flakey-bit opened this issue Jun 27, 2019 · 0 comments
Open

Array gaps not handled efficently #32

flakey-bit opened this issue Jun 27, 2019 · 0 comments

Comments

@flakey-bit
Copy link

Consider the following two sorted arrays:

Left: [1,2,3,4,5,6,7,8,9]
Right: [1,3,4,6,8]

Under the reference (JS) implementation we get an efficent output:

{
  "_t": "a",
  "_1": [
    2,
    0,
    0
  ],
  "_4": [
    5,
    0,
    0
  ],
  "_6": [
    7,
    0,
    0
  ],
  "_8": [
    9,
    0,
    0
  ]
}

telling us clearly that items at indexes 1, 4, 6 & 8 (i.e. values 2, 5, 7 & 9) have been removed.

Under jsondiffpatch.net

void Main()
{
	var leftArray = new int[] {
		1,
		2,
		3,
		4,
		5,
		6,
		7,
		8,
		9,
	};

	var rightArray = new int[] {
		1,
		3,
		4,
		6,
		8
	};

	var jdp = new JsonDiffPatch();
	var output = jdp.Diff(JToken.FromObject(leftArray), JToken.FromObject(rightArray));
	
	Console.Out.WriteLine(output.ToString());
}

We get the following output:

{
  "_t": "a",
  "_1": [
    2,
    0,
    0
  ],
  "_2": [
    3,
    0,
    0
  ],
  "_3": [
    4,
    0,
    0
  ],
  "_4": [
    5,
    0,
    0
  ],
  "_5": [
    6,
    0,
    0
  ],
  "_6": [
    7,
    0,
    0
  ],
  "_7": [
    8,
    0,
    0
  ],
  "_8": [
    9,
    0,
    0
  ],
  "1": [
    3
  ],
  "2": [
    4
  ],
  "3": [
    6
  ],
  "4": [
    8
  ]
}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant