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/real-order-stats.sml
ViewVC logotype

Diff of /sml/trunk/src/smlnj-lib/Util/real-order-stats.sml

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

revision 1732, Thu Dec 16 05:07:47 2004 UTC revision 1733, Thu Dec 16 05:37:04 2004 UTC
# Line 8  Line 8 
8   *)   *)
9  structure RealOrderStats : sig  structure RealOrderStats : sig
10    
11        (* WARNING: Each of the functions exported from this module
12         * modifies its argument array by (partially) sorting it. *)
13    
14      (* select the i-th order statistic *)      (* select the i-th order statistic *)
15      val select  : real array * int -> real      val select  : real array * int -> real
16      val select' : real ArraySlice.slice * int -> real      val select' : real ArraySlice.slice * int -> real
# Line 54  Line 57 
57          in rs (p, r) end          in rs (p, r) end
58    
59      fun select (a, i) = select0 (a, 0, Array.length a - 1, i)      fun select (a, i) = select0 (a, 0, Array.length a - 1, i)
60      fun select' (s, i) = let val (a, p, l) = ArraySlice.base s      fun select' (s, i) =
61                           in select0 (a, p, p+l-1, p+i) end          let val (a, p, l) = ArraySlice.base s in select0 (a, p, p+l-1, p+i) end
62    
63      fun median0 (a, p, len) =      fun median0 (a, p, len) =
64          let val mid = p + len div 2          let val mid = p + len div 2
65              val r = p + len - 1              val r = p + len - 1
66              val m0 = select0 (a, p, r, mid)              val m0 = select0 (a, p, r, mid)
67          in if len mod 2 = 1 then m0              fun l(i,m) = if i>=mid then m else l(i+1, Real.max(a$i,m))
68             else let fun l(i,m) = if i>=mid then m else l(i+1, Real.max(a$i,m))          in if len mod 2 = 1 then m0 else (l(p+1,a$p) + m0) / 2.0
                 in (l(p+1,a$p) + m0) / 2.0 end  
69          end          end
70    
71      fun median a = median0 (a, 0, Array.length a)      fun median a = median0 (a, 0, Array.length a)

Legend:
Removed from v.1732  
changed lines
  Added in v.1733

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