-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Separate core algo into a more generic version #12
base: main
Are you sure you want to change the base?
Conversation
@praeclarum I am afraid I am unable to see the details of the Bitrise check to understand what caused it to fail. Locally, |
The Bitrise errors are just missing XML comments. Hopefully you'll see them with a release build. This is really great. I like it a lot, especially if the public API doesn't break. I am a tiny bit concerned with performance only because complex generic uses can cause heavy trampolining on iOS and other AOT scenarios. It's one of the reasons I didn't include the generic equality comparer in the first place. That said, nothing about your re-architecture should be inefficient. I think it will behove the library to have some microbenchmarks. I can try to write some in master for comparison. I still need to review the code, but I like everything from your description. |
Yes, I see them with
That's great to hear!
I see. I wasn't aware of those as I don't do much mobile development. Anywhere I can read up on that?
Awesome and looking forward to your review. Thanks for your feedback in the meantime. |
This is just to fix release builds for now and will be fleshed post initial PR review.
I've put doc comments as to-do with 9e67da4 for now and the Bitrise check is passing now. I'll put the actual doc comments when you give me the go to move forward. |
I would have opened an issue first but some ideas and benefits are easier to demonstrate as a PR and working example, so here goes…
This PR primarily separates the diff algorithm from supporting types
ListDiffAction<,>
,ListDiffActionType
andListDiff<,>
and renders it even more generic so that it can stand and be used on its own; this leads to many benefits.First and foremost, the core function becomes very generic:
The 3 functions
updateResult
,addResult
andremoveResult
project the result elements such that the function can return a simple list (List<>
) of those results. The shape ofR
is now up to the caller based on relevant inputs.The constructor of
ListDiff<,>
has been updated to use it as follows:The are several other overloads added for convenience. For example, when source and destination elements are the same some type T then you get a simpler signature:
This uses the default comparer (
EqualityComparer<T>.Default
) so a function to determine a match isn't needed. This also solves the boxing/performance problem highlighted in issue #8.Since we have tuples, we can go one step further for simpler scenarios with the following signature:
That is, given 3 tags to represent an update, add or remove node, the function will return a list of triplets where the source and destinations elements are annotated with the appropriate tag.
In its current design, the stand-alone
Diff
method is part of a class calledDiffModule
. This permits using the method directly via a static import (using static ListDiff.DiffModule
).I have also placed
DiffModule
in its own file and made the definition partial and private by default. Then inListDiff.cs
, the partial definition has thepublic
modifier to make it public. The idea behind this seemingly bizarre approach is that it enables someone to just takeDiff.cs
and run with it in their project without inheriting any dependencies or types of the project.DiffModule
will automatically become a private artifact of the user's project. However, when included together withListDiff.cs
as part of this project, it is exposed publicly.If you like what you see here, I am happy to put polishing touches like doc comments and argument validation.
Looking forward to your review and thoughts.