X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=helm%2Focaml%2Fmathql_interpreter%2Fsortedby.ml;h=b9a05a00274e8846418be32c44c8f2f4b5f52837;hb=6cd9c31edf69f619789a9802e840fbb61f4b6b40;hp=a629266840608b6c2b5eb415ac05a3b29ccffdd8;hpb=8abd42ec1af0d5daef1d026ec550b49b07de8340;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/sortedby.ml b/helm/ocaml/mathql_interpreter/sortedby.ml index a62926684..b9a05a002 100644 --- a/helm/ocaml/mathql_interpreter/sortedby.ml +++ b/helm/ocaml/mathql_interpreter/sortedby.ml @@ -20,14 +20,14 @@ * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, - * http://cs.unibo.it/helm/. + * http://www.cs.unibo.it/helm/. *) (* * implementazione del comando SORTEDBY *) -open Mathql;; +open MathQL;; open Func;; open Utility;; @@ -35,20 +35,28 @@ open Utility;; * implementazione del comando SORTEDBY *) let sortedby_ex alist order afunc = - [List.hd alist] - @ - List.map - (List.tl) - (Sort.list - (fun a b -> - match order with - MQAsc -> (List.hd a) < (List.hd b) - | MQDesc -> (List.hd a) > (List.hd b) - ) - (List.map - (fun l -> [apply_func afunc (List.hd l)] @ l) - (List.tl alist) - ) - ) + let before = Sys.time () in + let res = + let module S = Mathql_semantics in + (Sort.list + (fun {S.extra = e1} {S.extra = e2} -> + match order with + MQAsc -> e1 < e2 + | MQDesc -> e1 > e2 + ) + (List.map + (fun {S.uri = u ; S.attributes = attr} -> {S.uri = u ; S.attributes = attr ; S.extra = (apply_func afunc u)}) + alist + ) + ) + in + let after = Sys.time () + and ll1 = string_of_int (List.length alist) in + let diff = string_of_float (after -. before) in + print_endline + ("SORTEDBY(" ^ ll1 ^ ") = " ^ string_of_int (List.length res) ^ + ": " ^ diff ^ "s") ; + flush stdout ; + res ;;