Skip to content

Map difference#12

Merged
dlesbre merged 15 commits intomainfrom
map-difference
Jul 24, 2024
Merged

Map difference#12
dlesbre merged 15 commits intomainfrom
map-difference

Conversation

@dlesbre
Copy link
Collaborator

@dlesbre dlesbre commented Jul 22, 2024

Add two difference functions:

  • domain_difference m1 m2 which is just m1 restricted to elements that don't appear in m2. On set, this is the Stdlib's diff function. Also defined for WithForeign operations.
  • difference f m1 m2 which returns the set of bindings that differ in m1 and m2, combining bindings present in both with f.

@dlesbre dlesbre requested a review from mlemerre July 22, 2024 11:45
@dlesbre dlesbre added the enhancement New feature or request label Jul 22, 2024
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
Copy link
Contributor

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?

(** 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
Copy link
Contributor

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

Copy link
Collaborator Author

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

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
Copy link
Contributor

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
Copy link
Contributor

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?

@dlesbre dlesbre merged commit 4b08d34 into main Jul 24, 2024
@dlesbre dlesbre deleted the map-difference branch July 24, 2024 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants