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/binary-map-fn.sml
ViewVC logotype

Diff of /sml/trunk/src/smlnj-lib/Util/binary-map-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1192, Wed May 15 14:02:06 2002 UTC revision 1193, Thu May 16 18:44:04 2002 UTC
# Line 303  Line 303 
303    
304      end (* local *)      end (* local *)
305    
306  (* the following are generic implementations of the unionWith and intersectWith  (* the following are generic implementations of the unionWith, intersectWith,
307   * operetions.  These should be specialized for the internal representations   * and mergeWith operetions.  These should be specialized for the internal
308   * at some point.   * representations at some point.
309   *)   *)
310      fun unionWith f (m1, m2) = let      fun unionWith f (m1, m2) = let
311            fun ins  f (key, x, m) = (case find(m, key)            fun ins  f (key, x, m) = (case find(m, key)
# Line 359  Line 359 
359                else intersect (fn (k, a, b) => f(k, b, a)) (m2, m1)                else intersect (fn (k, a, b) => f(k, b, a)) (m2, m1)
360            end            end
361    
362        fun mergeWith f (m1, m2) = let
363              fun merge ([], [], m) = m
364                | merge ((k1, x1)::r1, [], m) = mergef (k1, SOME x1, NONE, r1, [], m)
365                | merge ([], (k2, x2)::r2, m) = mergef (k2, NONE, SOME x2, [], r2, m)
366                | merge (m1 as ((k1, x1)::r1), m2 as ((k2, x2)::r2), m) = (
367                    case Key.compare (k1, k2)
368                     of LESS => mergef (k1, SOME x1, NONE, r1, m2, m)
369                      | EQUAL => mergef (k1, SOME x1, SOME x2, r1, r2, m)
370                      | GREATER => mergef (k2, NONE, SOME x2, m1, r2, m)
371                    (* end case *))
372              and mergef (k, x1, x2, r1, r2, m) = (case f (x1, x2)
373                     of NONE => merge (r1, r2, m)
374                      | SOME y => merge (r1, r2, insert(m, k, y))
375                    (* end case *))
376              in
377                merge (listItemsi m1, listItemsi m2, empty)
378              end
379        fun mergeWithi f (m1, m2) = let
380              fun merge ([], [], m) = m
381                | merge ((k1, x1)::r1, [], m) = mergef (k1, SOME x1, NONE, r1, [], m)
382                | merge ([], (k2, x2)::r2, m) = mergef (k2, NONE, SOME x2, [], r2, m)
383                | merge (m1 as ((k1, x1)::r1), m2 as ((k2, x2)::r2), m) = (
384                    case Key.compare (k1, k2)
385                     of LESS => mergef (k1, SOME x1, NONE, r1, m2, m)
386                      | EQUAL => mergef (k1, SOME x1, SOME x2, r1, r2, m)
387                      | GREATER => mergef (k2, NONE, SOME x2, m1, r2, m)
388                    (* end case *))
389              and mergef (k, x1, x2, r1, r2, m) = (case f (k, x1, x2)
390                     of NONE => merge (r1, r2, m)
391                      | SOME y => merge (r1, r2, insert(m, k, y))
392                    (* end case *))
393              in
394                merge (listItemsi m1, listItemsi m2, empty)
395              end
396    
397    (* this is a generic implementation of filter.  It should    (* this is a generic implementation of filter.  It should
398     * be specialized to the data-structure at some point.     * be specialized to the data-structure at some point.
399     *)     *)

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

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0