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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculating destination offset from source offset #10
Calculating destination offset from source offset #10
Conversation
Thanks for using FlexibleDiff & raising this. I did run into a similar problem lately, and changing the source of derivation does not seem to be the solution. Apparently, this way of deriving indices is busted by complications of moves, and it is unfortunate that the test coverage is not sufficient in this area. As an example:
Neither the current implementation nor that in this PR would correct the issue when, say, attempting to derive C's index in both direction. At this point I think a more rigid approach is to give |
Right, I didn't take that case into account 馃槢 I managed to create that test and check why the index derivation was not correct and was able to fix it. However, probably I'm missing some scenarios and your suggestion of giving access to the diffing algorithm's data structures would be safer. |
Hmm I think this is solid enough for the time being. Can't think of other boundary cases just yet. |
|
||
var insertionsBeforeOffset = IndexSet() | ||
for insertion in allInsertions where insertion <= postRemovalOffset + insertionsBeforeOffset.count { | ||
insertionsBeforeOffset.insert(insertion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you break the loop when the predicate is not satisfied? There is little value to continue iterating afterwards.
destination: offset, | ||
isMutated: isMutated)) | ||
moves.append(Changeset.Move(source: sourceOffset, | ||
destination: destinationOffset, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Nit] I guess one of the tab vs space argument is that Xcode sucks with handling tabs...
predeletionOffset = preinsertionOffset + allRemovals.count(in: 0 ... preinsertionOffset) | ||
let postRemovalOffset = sourceOffset - allRemovals.count(in: 0 ..< sourceOffset) | ||
|
||
var insertionsBeforeOffset = IndexSet() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just a counter instead of an IndexSet
. We do not care about the actual indices here.
Updated PR with code review suggestions and branch update 馃槂 |
Hello 馃憢
While using FlexibleDiff I ran into a situation where the generated
SectionedChangeset
seems to not be correct.I've added the following test which is failing:
The previous test fails with the following error:
Which means that the generated
SectionedChangeset
is something likeThis tells us that:
The problem seems to be that the
predeletionOffset
on theSectionedChangeset
'sinit
method is not being calculated correctly for this specific case.My suggestion in this PR is to start traversing the
previous
collection of sections and calculate adestinationOffset
for that section.By doing this we are able to know how many deletions and insertions will be performed up until the source index and we can calculate correctly what will be the section's index on the current collection.
Great library 馃憦 Keep up the good work 馃槂