From: "Daniel Bünzli" <daniel.buenzli@epfl.ch>
To: tmp123@menta.net
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Sorted list
Date: Sat, 4 Aug 2007 14:16:02 +0200 [thread overview]
Message-ID: <E1D56FCB-112D-46AD-A4CA-464A060C9FAE@epfl.ch> (raw)
In-Reply-To: <46B4485B.7040406@menta.net>
Le 4 août 07 à 11:35, tmp123@menta.net a écrit :
> Please, has someone any sugestion?
I once did that by using a leftist heap. Your abstract timerid can
have a mutable field that indicates if it was cancelled. When you
peek/pop for the minimal one do it until you get on a timer that was
not cancellled.
Daniel
P.S. You can use the following code for the heap. Public domain no
license, no copyright.
(* A leftist heap data structure. *)
module Heap = struct
type priority = float
type 'a t =
| Empty
| Node of 'a t * int * priority * 'a * 'a t
let rank = function
| Empty -> 0
| Node (_, r, _, _, _) -> r
let make_node p v h h' =
let r = rank h in
let r' = rank h' in
if r >= r' then Node(h, r' + 1, p, v, h')
else Node(h', r + 1, p, v, h)
let rec merge h h' = match h, h' with
| h, Empty -> h
| Empty, h -> h'
| Node(a, _, p, v, b), Node (a', _, p', v', b') ->
if p <= p' then make_node p v a (merge b h')
else make_node p' v' a' (merge b' h)
let empty = Empty
let is_empty = function
| Empty -> true
| _ -> false
let add h p v = merge (Node(Empty, 1, p, v, Empty)) h
let min = function
| Empty -> raise Not_found
| Node(_, _, p, v, _) -> p, v
let remove_min = function
| Empty -> raise Not_found
| Node(a, _, _, _, b) -> merge a b
end
next prev parent reply other threads:[~2007-08-04 12:15 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-04 9:35 tmp123
2007-08-04 10:00 ` [Caml-list] " Jon Harrop
2007-08-04 10:29 ` Philippe Wang
2007-08-04 11:22 ` skaller
2007-08-04 12:23 ` Philippe Wang
2007-08-04 13:39 ` skaller
2007-08-04 14:01 ` Philippe Wang
2007-08-04 14:45 ` skaller
2007-08-04 14:27 ` tmp123
2007-08-04 20:33 ` Christophe TROESTLER
2007-08-04 14:37 ` tmp123
2007-08-04 15:09 ` Brian Hurt
2007-08-04 15:42 ` skaller
2007-08-04 16:21 ` Richard Jones
2007-08-04 17:17 ` Brian Hurt
2007-08-04 18:24 ` skaller
2007-08-04 17:54 ` skaller
2007-08-04 19:16 ` Richard Jones
2007-08-05 16:22 ` David Allsopp
2007-08-05 16:41 ` Xavier Leroy
2007-08-05 17:01 ` David Allsopp
2007-08-04 17:35 ` Julien Moutinho
2007-08-04 18:04 ` skaller
2007-08-05 1:47 ` Jon Harrop
2007-08-05 11:44 ` Erik de Castro Lopo
2007-08-05 12:03 ` Jacques GARRIGUE
2007-08-05 12:31 ` Erik de Castro Lopo
2007-08-05 13:22 ` Richard Jones
2007-08-05 20:47 ` Erik de Castro Lopo
2007-08-05 13:17 ` Richard Jones
2007-08-05 16:26 ` Xavier Leroy
2007-08-05 23:47 ` skaller
2007-08-04 15:36 ` skaller
2007-08-04 15:17 ` tmp123
2007-08-12 12:05 ` Andrej Bauer
2007-08-04 12:15 ` Brian Hurt
2007-08-04 12:36 ` Brian Hurt
2007-08-04 13:49 ` skaller
2007-08-04 12:16 ` Daniel Bünzli [this message]
2007-08-04 12:58 ` Oliver Bandel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1D56FCB-112D-46AD-A4CA-464A060C9FAE@epfl.ch \
--to=daniel.buenzli@epfl.ch \
--cc=caml-list@yquem.inria.fr \
--cc=tmp123@menta.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox