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/trunk/Util/list-set-fn.sml
ViewVC logotype

Diff of /smlnj-lib/trunk/Util/list-set-fn.sml

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

revision 3716, Sat Mar 10 23:44:59 2012 UTC revision 3717, Mon Mar 26 10:59:31 2012 UTC
# Line 1  Line 1 
1  (* list-set-fn.sml  (* list-set-fn.sml
2   *   *
3   * COPYRIGHT (c) 1996 by AT&T Research.  See COPYRIGHT file for details.   * COPYRIGHT (c) 1996 by AT&T Research.  See COPYRIGHT file for details.
4     * COPYRIGHT (c) 2012 The Fellowship of SML/NJ (http://www.smlnj.org)
5     * All rights reserved.
6   *   *
7   * An implementation of finite sets of ordered values, which uses a sorted list   * An implementation of finite sets of ordered values, which uses a sorted list
8   * representation.   * representation.
# Line 73  Line 75 
75              union (l, items')              union (l, items')
76            end            end
77    
78        fun subtract (l, item) = let
79              fun f ([], _) = l
80                | f (elem::r, prefix) = (case Key.compare(item, elem)
81                       of LESS => l
82                        | EQUAL => List.revAppend(prefix, r)
83                        | GREATER => f (r, elem::prefix)
84                      (* end case *))
85              in
86                f (l, [])
87              end
88        fun subtract' (item, l) = subtract (l, item)
89    
90        fun subtractList (l, items) = let
91              val items' = List.foldl (fn (x, set) => add(set, x)) [] items
92              in
93                difference (l, items')
94              end
95    
96    (* create a set from a list of items; this function works in linear time if the list    (* create a set from a list of items; this function works in linear time if the list
97     * is in increasing order.     * is in increasing order.
98     *)     *)

Legend:
Removed from v.3716  
changed lines
  Added in v.3717

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