(* Copyright (C) 2000, HELM Team. * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science * Department, University of Bologna, Italy. * * HELM is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * HELM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HELM; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, * http://cs.unibo.it/helm/. *) (* AUTOR: Ferruccio Guidi *) (* time handling ***********************************************************) type time = float * float let start_time () = (Sys.time (), Unix.time ()) let stop_time (s0, u0) = let s1 = Sys.time () in let u1 = Unix.time () in Printf.sprintf "%.2fs,%.2fs" (s1 -. s0) (u1 -. u0) (* operations on lists *****************************************************) type 'a comparison = Lt | Gt | Eq of 'a let list_join f l1 l2 = let rec aux = function | [], v | v, [] -> v | ((h1 :: t1) as v1), ((h2 :: t2) as v2) -> begin match f h1 h2 with | Lt -> h1 :: aux (t1, v2) | Gt -> h2 :: aux (v1, t2) | Eq h -> h :: aux (t1, t2) end in aux (l1, l2) let list_meet f l1 l2 = let rec aux = function | [], v | v, [] -> [] | ((h1 :: t1) as v1), ((h2 :: t2) as v2) -> begin match f h1 h2 with | Lt -> aux (t1, v2) | Gt -> aux (v1, t2) | Eq h -> h :: aux (t1, t2) end in aux (l1, l2) let rec flat_list out f s = function | [] -> () | [a] -> f a | a :: tail -> f a; out s; flat_list out f s tail let rec add_assoc ap = function | [] -> [ap] | head :: tail when fst head = fst ap -> ap :: tail | head :: tail -> head :: add_assoc ap tail (* int of string ************************************************************) type t = End | Space | Figure of int | Error let int_of_string s = let l = String.length s in let get_t i = if i = l then End else match s.[i] with | ' ' | '\t' | '\r' | 'n' -> Space | '0' .. '9' -> Figure (Char.code s.[i] - Char.code '0') | _ -> Error in let rec aux i xv = match get_t i, xv with | Error, _ | End, None -> raise (Failure "int_of_string") | End, Some v -> v | Space, xv -> aux (succ i) xv | Figure f, None -> aux (succ i) (Some f) | Figure f, Some v -> aux (succ i) (Some (10 * v + f)) in aux 0 None