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 /smlnj-lib/branches/rt-transition/Util/splay-map-fn.sml
ViewVC logotype

Diff of /smlnj-lib/branches/rt-transition/Util/splay-map-fn.sml

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

revision 651, Thu Jun 1 18:34:03 2000 UTC revision 1193, Thu May 16 18:44:04 2002 UTC
# Line 249  Line 249 
249            MAP{root = ref(ap (!root)), nobj = nobj}            MAP{root = ref(ap (!root)), nobj = nobj}
250          end          end
251    
252  (* the following are generic implementations of the unionWith and intersectWith  (* the following are generic implementations of the unionWith, intersectWith,
253   * operetions.  These should be specialized for the internal representations   * and mergeWith operetions.  These should be specialized for the internal
254   * at some point.   * representations at some point.
255   *)   *)
256      fun unionWith f (m1, m2) = let      fun unionWith f (m1, m2) = let
257            fun ins f (key, x, m) = (case find(m, key)            fun ins f (key, x, m) = (case find(m, key)
# Line 306  Line 306 
306                else intersect (fn (k, a, b) => f(k, b, a)) (m2, m1)                else intersect (fn (k, a, b) => f(k, b, a)) (m2, m1)
307            end            end
308    
309        fun mergeWith f (m1, m2) = let
310              fun merge ([], [], m) = m
311                | merge ((k1, x1)::r1, [], m) = mergef (k1, SOME x1, NONE, r1, [], m)
312                | merge ([], (k2, x2)::r2, m) = mergef (k2, NONE, SOME x2, [], r2, m)
313                | merge (m1 as ((k1, x1)::r1), m2 as ((k2, x2)::r2), m) = (
314                    case Key.compare (k1, k2)
315                     of LESS => mergef (k1, SOME x1, NONE, r1, m2, m)
316                      | EQUAL => mergef (k1, SOME x1, SOME x2, r1, r2, m)
317                      | GREATER => mergef (k2, NONE, SOME x2, m1, r2, m)
318                    (* end case *))
319              and mergef (k, x1, x2, r1, r2, m) = (case f (x1, x2)
320                     of NONE => merge (r1, r2, m)
321                      | SOME y => merge (r1, r2, insert(m, k, y))
322                    (* end case *))
323              in
324                merge (listItemsi m1, listItemsi m2, empty)
325              end
326    
327        fun mergeWithi f (m1, m2) = let
328              fun merge ([], [], m) = m
329                | merge ((k1, x1)::r1, [], m) = mergef (k1, SOME x1, NONE, r1, [], m)
330                | merge ([], (k2, x2)::r2, m) = mergef (k2, NONE, SOME x2, [], r2, m)
331                | merge (m1 as ((k1, x1)::r1), m2 as ((k2, x2)::r2), m) = (
332                    case Key.compare (k1, k2)
333                     of LESS => mergef (k1, SOME x1, NONE, r1, m2, m)
334                      | EQUAL => mergef (k1, SOME x1, SOME x2, r1, r2, m)
335                      | GREATER => mergef (k2, NONE, SOME x2, m1, r2, m)
336                    (* end case *))
337              and mergef (k, x1, x2, r1, r2, m) = (case f (k, x1, x2)
338                     of NONE => merge (r1, r2, m)
339                      | SOME y => merge (r1, r2, insert(m, k, y))
340                    (* end case *))
341              in
342                merge (listItemsi m1, listItemsi m2, empty)
343              end
344    
345    (* this is a generic implementation of mapPartial.  It should    (* this is a generic implementation of mapPartial.  It should
346     * be specialized to the data-structure at some point.     * be specialized to the data-structure at some point.
347     *)     *)

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

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