Home My Page Projects Code Snippets Project Openings SML/NJ
 Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

# SCM Repository

[smlnj] Diff of /sml/trunk/src/smlnj-lib/Util/int-list-map.sml
 [smlnj] / sml / trunk / src / smlnj-lib / Util / int-list-map.sml

# Diff of /sml/trunk/src/smlnj-lib/Util/int-list-map.sml

revision 651, Thu Jun 1 18:34:03 2000 UTC revision 1193, Thu May 16 18:44:04 2002 UTC
# Line 158  Line 158
158              merge (m1, m2, [])              merge (m1, m2, [])
159            end            end
160
161        fun mergeWith f (m1 : 'a map, m2 : 'b map) = let
162              fun merge (m1 as ((k1, x1)::r1), m2 as ((k2, x2)::r2), l) =
163                    if (k1 < k2)
164                      then mergef (k1, SOME x1, NONE, r1, m2, l)
165                    else if (k1 = k2)
166                      then mergef (k1, SOME x1, SOME x2, r1, r2, l)
167                      else mergef (k2, NONE, SOME x2, m1, r2, l)
168                | merge ([], [], l) = List.rev l
169                | merge ((k1, x1)::r1, [], l) = mergef (k1, SOME x1, NONE, r1, [], l)
170                | merge ([], (k2, x2)::r2, l) = mergef (k2, NONE, SOME x2, [], r2, l)
171              and mergef (k, x1, x2, r1, r2, l) = (case f (x1, x2)
172                     of NONE => merge (r1, r2, l)
173                      | SOME y => merge (r1, r2, (k, y)::l)
174                    (* end case *))
175              in
176                merge (m1, m2, [])
177              end
178        fun mergeWithi f (m1 : 'a map, m2 : 'b map) = let
179              fun merge (m1 as ((k1, x1)::r1), m2 as ((k2, x2)::r2), l) =
180                    if (k1 < k2)
181                      then mergef (k1, SOME x1, NONE, r1, m2, l)
182                    else if (k1 = k2)
183                      then mergef (k1, SOME x1, SOME x2, r1, r2, l)
184                      else mergef (k2, NONE, SOME x2, m1, r2, l)
185                | merge ([], [], l) = List.rev l
186                | merge ((k1, x1)::r1, [], l) = mergef (k1, SOME x1, NONE, r1, [], l)
187                | merge ([], (k2, x2)::r2, l) = mergef (k2, NONE, SOME x2, [], r2, l)
188              and mergef (k, x1, x2, r1, r2, l) = (case f (k, x1, x2)
189                     of NONE => merge (r1, r2, l)
190                      | SOME y => merge (r1, r2, (k, y)::l)
191                    (* end case *))
192              in
193                merge (m1, m2, [])
194              end
195
196    (* Apply a function to the entries of the map in map order. *)    (* Apply a function to the entries of the map in map order. *)
197      val appi = List.app      val appi = List.app
198      fun app f l = appi (fn (_, item) => f item) l      fun app f l = appi (fn (_, item) => f item) l

Legend:
 Removed from v.651 changed lines Added in v.1193