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.1 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 E6F63BC6B for ; Sat, 4 Aug 2007 13:22:26 +0200 (CEST) Received: from ipmail01.adl2.internode.on.net (ipmail01.adl2.internode.on.net [203.16.214.140]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l74BMO9J010544 for ; Sat, 4 Aug 2007 13:22:26 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAGb7s0Z5LGJp/2dsb2JhbAAN X-IronPort-AV: E=Sophos;i="4.19,220,1183300200"; d="scan'208";a="167026238" Received: from ppp121-44-98-105.lns10.syd6.internode.on.net (HELO [192.168.1.201]) ([121.44.98.105]) by ipmail01.adl2.internode.on.net with ESMTP; 04 Aug 2007 20:52:21 +0930 Subject: Re: [Caml-list] Sorted list From: skaller To: Philippe Wang Cc: tmp123@menta.net, ocaml ml In-Reply-To: <46B454ED.700@philippewang.info> References: <46B4485B.7040406@menta.net> <46B454ED.700@philippewang.info> Content-Type: text/plain Date: Sat, 04 Aug 2007 21:22:18 +1000 Message-Id: <1186226538.14440.105.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 46B46170.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; 0200,:01 elt:01 sugestion:01 functor:01 sig:01 val:01 unit-:01 inserting:01 sourceforge:01 wrote:01 wrote:01 caml-list:01 functions:01 int:01 data:02 On Sat, 2007-08-04 at 12:29 +0200, Philippe Wang wrote: > tmp123@menta.net wrote: > > 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. You cannot do that! compare function must be a total order. You must keep a list of functions to fire off at a given time, so the map will be time -> timerid list and you'll also need timerid -> time * (unit->unit) to fetch the function from the id. If you want "high performance" interrupt handling then you should also: (A) put close timers into the same list (B) before returning from the interrupt,check to see if there is another function to execute at a time less than NOW + some constant. Given those requirements a good data structure is not so easy to find. A list is probably the best, assuming interrupt performance is more important than inserting and deleting timers. -- John Skaller Felix, successor to C++: http://felix.sf.net