Version française
Home     About     Download     Resources     Contact us    
Browse thread
Sorted list
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Sorted list
Hello,

do you have no real name?


Zitat von tmp123@menta.net:
[...]
>
> 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?
>
[...]


You can make the type of the Set a pair,
with the time and the timerid (if it is created in
ascending order) as it's elements.

Then you can compare the time and the id.
Ocaml makes this for you easy:


========================================================

oliver@siouxsie2:~$ ocaml
        Objective Caml version 3.09.2

# let pl = [("12:17:22", 20); ("13:44:23", 3); ("12:17:22", 2);
  ("12:17:22",1); ("12:17:22",12)];;
val pl : (string * int) list =
  [("12:17:22", 20); ("13:44:23", 3); ("12:17:22", 2); ("12:17:22", 1);
   ("12:17:22", 12)]
# List.sort compare pl;;
- : (string * int) list =
[("12:17:22", 1); ("12:17:22", 2); ("12:17:22", 12); ("12:17:22", 20);
 ("13:44:23", 3)]
#
========================================================

So, a simple compare would also work for your Set.

Ciao,