Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[fix] map: Intersection with an empty map now sends an empty map

  • Loading branch information...
commit 646c1bd11088bb2d3821576c537f5ab7d3c8c75e 1 parent 9a4a8ee
Nicolas Glondu authored
Showing with 5 additions and 7 deletions.
  1. +5 −7 stdlib/core/map/map.opa
12 stdlib/core/map/map.opa
View
@@ -837,6 +837,7 @@ Map_make(order: order('key,'order) ) : Map =
* If a key appears in both maps with distinct values, one of the values
* is chosen arbitrarily.
*
+ * @TODO optimize
*/
intersection(map1, map2) =
rec aux(m1: Map_private.map('key, 'val),
@@ -850,13 +851,10 @@ Map_make(order: order('key,'order) ) : Map =
if mem(key : 'key, m2) then add(key : 'key, value : 'val, acc)
else acc
- match (is_empty(map1), is_empty(map2)) with
- | ({ true }, { false }) -> map2
- | ({ false }, { true }) -> map1
- | _ ->
- if height(map1) < height(map2) then aux(map1, map2, empty)
- else aux(map2, map1, empty)
-
+ if is_empty(map1) || is_empty(map2) then empty
+ else
+ if height(map1) < height(map2) then aux(map1, map2, empty)
+ else aux(map2, map1, empty)
From = {{
Please sign in to comment.
Something went wrong with that request. Please try again.