From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=AWL,MAILTO_TO_SPAM_ADDR autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 26DB7BC6B for ; Sat, 4 Aug 2007 12:29:09 +0200 (CEST) Received: from 30.mail-out.ovh.net (30.mail-out.ovh.net [213.186.62.213]) by discorde.inria.fr (8.13.6/8.13.6) with SMTP id l74AT8ww002118 for ; Sat, 4 Aug 2007 12:29:08 +0200 Received: (qmail 19587 invoked by uid 503); 4 Aug 2007 10:29:32 -0000 Received: (QMFILT: 1.0); 04 Aug 2007 10:29:32 -0000 Received: from b7.ovh.net (HELO mail93.ha.ovh.net) (213.186.33.57) by 30.mail-out.ovh.net with SMTP; 4 Aug 2007 10:29:32 -0000 Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 4 Aug 2007 10:29:17 -0000 Received: from vil93-4-82-227-140-227.fbx.proxad.net (HELO ?192.168.1.222?) (82.227.140.227) by ns0.ovh.net with SMTP; 4 Aug 2007 10:29:15 -0000 Message-ID: <46B454ED.700@philippewang.info> Date: Sat, 04 Aug 2007 12:29:01 +0200 From: Philippe Wang User-Agent: Thunderbird 1.5.0.12 (Macintosh/20070509) MIME-Version: 1.0 To: tmp123@menta.net, ocaml ml Subject: Re: [Caml-list] Sorted list References: <46B4485B.7040406@menta.net> In-Reply-To: <46B4485B.7040406@menta.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Ovh-Remote: 82.227.140.227 (vil93-4-82-227-140-227.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Miltered: at discorde with ID 46B454F4.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; elt:01 sugestion:01 functor:01 sig:01 val:01 cheers:01 wrote:01 caml-list:01 int:01 modules:02 seems:03 module:03 module:03 unit:03 unit:03 tmp123@menta.net wrote: > Hello, > > In order to implement a timers subsystem, I need a module with the > following values: > > *) add_timer : time -> ( unit -> unit ) -> timerid, > for public usage, where "add_timer t f" means execute "f" at time > "t". The result is an identifier who allows cancelation of the timer. > *) cancel_timer: timerid -> unit > for public usage, cancel a previously added timer > *) peek_minimum_timer : unit -> ( time, unit -> unit ) > for internal usage, get the timer with minimum time. Returns the time > and the related function. > *) remove_minimum_timer : ?? -> unit > for internal usage, remove the timer with the minimum time. It will be > called after execute a timer. > > Thus, in a generic sense, what I need is a "sorted list", with easy > insertion of elements, and peek/pop of the head (minimum). > > Of the standard modules, the most similar seems "set", because allows > insertion and has the funcion "min_elt". However, the problem is, if > two timers have the same time, addition of the second one removes the > first. > > Please, has someone any sugestion? > > Thanks a lot. Hello, Let's remind that Set.Make is a functor that takes a module with sig type t val compare : t -> t -> int end If you simply give him a compare function that never returns 0, then you can add multiple elements that are the same. Cheers, -- Philippe Wang mail[at]philippewang.info