Skip to content

Commit 80aea03

Browse files
authored
Merge pull request herd#1731 from herd/upgrade-mymap
[lib] Modernise a few functions of the `MyMap`module Use `Map` stdlib `update` and `union` functions.
2 parents bf5d41e + 9a9f1ca commit 80aea03

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

lib/myMap.ml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ module Make(O:Set.OrderedType) : S with type key = O.t =
7676

7777
let pp_str pp_bind m = pp_str_delim ";" pp_bind m
7878

79-
8079
let pp chan pp_bind m =
8180
iter
8281
(fun k v -> pp_bind chan k v ; fprintf chan ";")
@@ -86,14 +85,7 @@ module Make(O:Set.OrderedType) : S with type key = O.t =
8685

8786
let union_std = union
8887

89-
let union u m1 m2 =
90-
fold
91-
(fun k v1 m ->
92-
try
93-
let v2 = find k m2 in
94-
add k (u v1 v2) m
95-
with Not_found -> add k v1 m)
96-
m1 m2
88+
let union u m1 m2 = union_std (fun _ v1 v2 -> Some (u v1 v2)) m1 m2
9789

9890
let unions u ms = match ms with
9991
| [] -> empty
@@ -111,7 +103,10 @@ module Make(O:Set.OrderedType) : S with type key = O.t =
111103
fun t acc -> fold fold_binding t acc
112104

113105
let accumulate k v m =
114-
let vs = safe_find [] k m in
115-
add k (v::vs) m
106+
update k
107+
(function
108+
| None -> Some [v]
109+
| Some vs -> Some (v::vs))
110+
m
116111

117112
end

0 commit comments

Comments
 (0)