Browse thread
Sorted list
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Philippe Wang <lists@p...> |
| Subject: | Re: [Caml-list] Sorted list |
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