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/comp-lib/sortedlist.sml
 [smlnj] / sml / trunk / src / comp-lib / sortedlist.sml

# Diff of /sml/trunk/src/comp-lib/sortedlist.sml

revision 418, Fri Sep 3 23:51:27 1999 UTC revision 429, Wed Sep 8 09:47:00 1999 UTC
# Line 8  Line 8
8    in  f l    in  f l
9    end    end
10
fun uniq l =
let fun loop([],acc) = acc
| loop(a::r,acc) = loop(r,enter(a,acc))
in loop(l,[])
end

11  fun merge(a,[]) = a  fun merge(a,[]) = a
12    | merge([],a) = a    | merge([],a) = a
13    | merge(l as (i:int)::a, m as j::b) =    | merge(l as (i:int)::a, m as j::b) =
# Line 24  Line 18
18  in fun foldmerge l = hd(loop l) handle Hd => []  in fun foldmerge l = hd(loop l) handle Hd => []
19  end  end
20
21    fun uniq l =
22        let fun split([],l,r) = (l,r)
23              | split(h::t,l,r) = split(t,r,h::l)
24            fun sort [] = []
25              | sort (l as [_]) = l
26              | sort (l as [x : int,y : int]) =
27                 if x = y then [x] else if x < y then l else [y,x]
28              | sort l = let val (l,r) = split(l,[],[])
29                         in  merge(sort l, sort r) end
30        in  sort l
31        end
32
33  fun remove(x as (xl:int)::xr, y as yl::yr) =  fun remove(x as (xl:int)::xr, y as yl::yr) =
34      if xl>yl then yl::remove(x,yr) else remove(xr,if xl<yl then y else yr)      if xl>yl then yl::remove(x,yr) else remove(xr,if xl<yl then y else yr)
35    | remove(_,y) = y    | remove(_,y) = y

Legend:
 Removed from v.418 changed lines Added in v.429