diff options
Diffstat (limited to 'lib/gmap.ml')
| -rw-r--r-- | lib/gmap.ml | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/gmap.ml b/lib/gmap.ml index 4febb3ad1d..858cb40c8b 100644 --- a/lib/gmap.ml +++ b/lib/gmap.ml @@ -8,7 +8,7 @@ (* $Id$ *) (* Maps using the generic comparison function of ocaml. Code borrowed from - the ocaml standard library. *) + the ocaml standard library (Copyright 1996, INRIA). *) type ('a,'b) t = Empty @@ -81,12 +81,23 @@ let c = Pervasives.compare x v in c = 0 || mem x (if c < 0 then l else r) - let rec merge t1 t2 = + let rec min_binding = function + Empty -> raise Not_found + | Node(Empty, x, d, r, _) -> (x, d) + | Node(l, x, d, r, _) -> min_binding l + + let rec remove_min_binding = function + Empty -> invalid_arg "Map.remove_min_elt" + | Node(Empty, x, d, r, _) -> r + | Node(l, x, d, r, _) -> bal (remove_min_binding l) x d r + + let merge t1 t2 = match (t1, t2) with (Empty, t) -> t | (t, Empty) -> t - | (Node(l1, v1, d1, r1, h1), Node(l2, v2, d2, r2, h2)) -> - bal l1 v1 d1 (bal (merge r1 l2) v2 d2 r2) + | (_, _) -> + let (x, d) = min_binding t2 in + bal t1 x d (remove_min_binding t2) let rec remove x = function Empty -> @@ -109,6 +120,9 @@ Empty -> Empty | Node(l, v, d, r, h) -> Node(map f l, v, f d, map f r, h) + (* Maintien de fold_right par compatibilité (changé en fold_left dans + ocaml-3.09.0) *) + let rec fold f m accu = match m with Empty -> accu |
