-
Notifications
You must be signed in to change notification settings - Fork 0
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
Map difference #12
Map difference #12
Conversation
src/signatures.ml
Outdated
val slow_merge : ('map1, 'map2, 'map3) polymerge -> 'map1 t -> 'map2 t -> 'map3 t | ||
(** This is the same as {{: https://ocaml.org/api/Map.S.html#VALmerge}Stdlib.Map.S.merge} *) | ||
|
||
val difference: ('a, 'a, 'a) polyinterfilter -> 'a t -> 'a t -> 'a t |
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 we should have type 'a difference = ('a,'a,'a) polyinterfilter?
src/signatures.ml
Outdated
val slow_merge : ('map1, 'map2, 'map3) polymerge -> 'map1 t -> 'map2 t -> 'map3 t | ||
(** This is the same as {{: https://ocaml.org/api/Map.S.html#VALmerge}Stdlib.Map.S.merge} *) | ||
|
||
val difference: ('a, 'a, 'a) polyinterfilter -> 'a t -> 'a t -> 'a t | ||
(** [difference f map1 map2] returns a map comprising of the bindings |
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 name this symmetric_difference? If I understood well what this function does
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.
Oh yes that's not a bad idea
src/signatures.ml
Outdated
@@ -507,6 +531,13 @@ module type HETEROGENEOUS_MAP = sig | |||
{!update_multiple_from_foreign}, except that instead of updating for all | |||
keys in [m_from], it only updates for keys that are both in [m_from] and | |||
[m_to]. *) | |||
|
|||
val domain_difference: 'a t -> 'b Map2.t -> 'a t |
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.
And this would be just difference
src/functors.ml
Outdated
let rec domain_difference ta tb = | ||
match NODE.view ta, NODE.view tb with | ||
| Empty, _ | _, Empty -> ta | ||
| Leaf{key;_},_ -> if mem key tb then empty else ta |
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.
Should we use a function on the values to know if we want to remove the binding or not?
Add two difference functions:
domain_difference m1 m2
which is justm1
restricted to elements that don't appear inm2
. On set, this is theStdlib
'sdiff
function. Also defined forWithForeign
operations.difference f m1 m2
which returns the set of bindings that differ inm1
andm2
, combining bindings present in both withf
.