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

SCM Repository

[smlnj] Annotation of /sml/trunk/src/comp-lib/sortedlist.sml
ViewVC logotype

Annotation of /sml/trunk/src/comp-lib/sortedlist.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 89 - (view) (download)

1 : monnier 89 (* Copyright 1989 by AT&T Bell Laboratories *)
2 :     structure SortedList =
3 :     struct
4 :    
5 :     fun enter(new:int,l) =
6 :     let fun f [] = [new]
7 :     | f (l as h::t) = if new<h then new::l else if new>h then h::f t else l
8 :     in f l
9 :     end
10 :    
11 :     fun uniq l =
12 :     let fun loop([],acc) = acc
13 :     | loop(a::r,acc) = loop(r,enter(a,acc))
14 :     in loop(l,[])
15 :     end
16 :    
17 :     fun merge(a,[]) = a
18 :     | merge([],a) = a
19 :     | merge(l as (i:int)::a, m as j::b) =
20 :     if j<i then j::merge(l,b) else i::merge(a,if i<j then m else b)
21 :    
22 :     local fun loop (a::b::rest) = loop(merge(a,b)::loop rest)
23 :     | loop l = l
24 :     in fun foldmerge l = hd(loop l) handle Hd => []
25 :     end
26 :    
27 :     fun remove(x as (xl:int)::xr, y as yl::yr) =
28 :     if xl>yl then yl::remove(x,yr) else remove(xr,if xl<yl then y else yr)
29 :     | remove(_,y) = y
30 :    
31 :     fun rmv (x : int,l) =
32 :     let fun loop nil = nil
33 :     | loop (a::b) = if x=a then b else a::loop b
34 :     in loop l
35 :     end
36 :    
37 :     fun member l (e:int) =
38 :     let fun f [] = false
39 :     | f (h::t) = if h<e then f t else e=h
40 :     in f l
41 :     end
42 :    
43 :     fun intersect(nil,_) = nil
44 :     | intersect(_,nil) = nil
45 :     | intersect(l as (a:int)::b,r as c::d) =
46 :     if a=c then a::intersect(b,d)
47 :     else if a<c then intersect(b,r)
48 :     else intersect(l,d)
49 :    
50 :     fun difference(nil,_) = nil
51 :     | difference(l,nil) = l
52 :     | difference(l as (a:int)::b,r as c::d) =
53 :     if a=c then difference(b,d)
54 :     else if a<c then a::difference(b,r)
55 :     else difference(l,d)
56 :     end
57 :    
58 :     (*
59 :     * $Log: sortedlist.sml,v $
60 :     * Revision 1.1.1.1 1998/04/08 18:39:13 george
61 :     * Version 110.5
62 :     *
63 :     *)

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