-
Notifications
You must be signed in to change notification settings - Fork 21
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
Support symmetric diff on maps and sets #768
Comments
There's a rough outline of where the code would have to go here: https://github.com/dotnet/fsharp/compare/master...dsyme:sd?expand=1 I started looking at the implementation but I notice that the implementation for set comparison looks like it allocates a lot. I'm wondering if someone would like to take a look at implementing a much more efficient set/map difference and comparison, which allocates a lot less. |
I updated the prototype for set diff'ing to use an imperative 'while' loop - I haven't tested it yet, nor performance-tested it |
I suspect for maximum performance (and lowest allocation) the diffing should probably use this signature:
rather than returning a sequence which is then enumerated. |
I was thinking of using
for For sets, |
What about a symmetricDiffFold ?
|
I was going to propose the same as @thinkbeforecoding regarding sets and |
I suggest edit: and thus, if we're also doing
Perhaps stick to |
I guess this is why returning |
BTW one annoying problem with |
Isn't it the case with tuples too ? |
What about
? |
Yes, though we could make it a struct tuple. FSharp.Core doesn't (yet) contain StructChoice unfortunately |
It would be odd to have one stdlib function use struct tuples in its signature while the rest of the stdlib uses ref tuples. Maybe it's time to add struct-based variants of all the relevant stdlib functions (eg zip, partition, etc) in dedicated modules? |
Hi everyone, quite some time ago we copied the map implementation from F# and extended it with some rather useful functions like Feel free to take whatever you want 😀 Another thing is that the count of the map can easily be maintained (and is in our fork) Cheers |
Forgot to mention: I'd be happy to migrate some of our changes back, and especially alter/choose2/unionWith would be nice to have. Just let me know it you're willing to give it a try and I'll put together a pull request. |
From fabulous-dev/Fabulous#258 (comment)
Watching Yaron Minsky's Strangeloop talk, I notice that F# immutable maps should likely support a "symmetric diff" operation with signature such as
The idea here is that the output sequence contains only elements where the two maps differ, returning the key and a choice between "left map only", "right map only" and "both but different values". Identical elements are not returned.
Sets should also support this with signature like:
where the bool indicates "left set only" or "right set only" and again identical elements are not returned. In both cases pointer equality n the internal trees for the maps/sets is used to avoid re-traversing entire data structures.
The talk also mentions an incrementalizing
diff
operation that relies on a particular incrementalization library for self-adjusting computations.Notes from the OCaml docs:
As an aside, I also notice
Map.merge
:Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: