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

Items that do not move show as being moved #32

Open
Chandlerdea opened this issue Apr 30, 2018 · 3 comments
Open

Items that do not move show as being moved #32

Chandlerdea opened this issue Apr 30, 2018 · 3 comments

Comments

@Chandlerdea
Copy link

Chandlerdea commented Apr 30, 2018

I am seeing some weird behavior when diffing arrays which have contents that do not move. Here is the scenario:

I have two arrays, which look like this:

Old array: ([Int]) $R90 = 20 values {
  [0] = 63
  [1] = 5
  [2] = 112
  [3] = 48
  [4] = 100006
  [5] = 121
  [6] = 33
  [7] = 65
  [8] = 100003
  [9] = 57
  [10] = 100007
  [11] = 117
  [12] = 108
  [13] = 1
  [14] = 118
  [15] = 100688
  [16] = 18
  [17] = 54
  [18] = 116
  [19] = 110
}
New array: ([Int]) $R91 = 20 values {
  [0] = 65
  [1] = 118
  [2] = 110
  [3] = 117
  [4] = 100006
  [5] = 112
  [6] = 1
  [7] = 54
  [8] = 116
  [9] = 100688
  [10] = 48
  [11] = 57
  [12] = 108
  [13] = 63
  [14] = 121
  [15] = 33
  [16] = 18
  [17] = 5
  [18] = 100003
  [19] = 100007
}

One of the patches returned the extendedPatch() function looks like this:

 [13] = move {
    move = (from = 20, to = 16)
  }

This is causing a crash in my app, because there is no item at index 20 in the array. You can see that the object at index 16 doesn't move, but for some reason the library is saying that it has moved.

@tonyarnold
Copy link
Owner

Would you mind showing me the code you're using to diff the arrays? A reproduction in a Playground would be a huge help if you have time.

@georgenavarro
Copy link

georgenavarro commented May 27, 2018

Hi,

I am seeing the same issue. I can reproduce simply by using this code:

var existingIds = [63, 5,   112, 48,  100006, 121, 33, 65, 100003, 57,     100007, 117, 108, 1,  118, 100688, 18, 54, 116,    110]
let incomingIds = [65, 118, 110, 117, 100006, 112, 1,  54, 116,    100688, 48,     57,  108, 63, 121, 33,     18, 5,  100003, 100007]
let idPatches = extendedPatch(from: existingIds, to: incomingIds)

These are the patches produced:

[M(0,4), M(0,7), M(6,0), M(14,1), M(19,2), M(13,3), M(7,4), M(15,6), M(18,7), M(19,8), M(18,9), M(16,11), M(19,12), M(20,16)]

Like @Chandlerdea says, the last patch would cause a crash due to index out of bounds.

@tonyarnold
Copy link
Owner

Thanks for the example, @georgenavarro - I appreciate it. I'm pretty busy at the moment, so I'm not sure when I'll have a chance to look at fixing this issue. If either of you gets a chance in the meantime, a PR with tests showing and/or fixing the problem are always welcome.

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

3 participants