Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Should be INSIDE STANDARD-LIB: Hashtbl.keys
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jdh30@c...>
Subject: Re: [Caml-list] Should be INSIDE STANDARD-LIB: Hashtbl.keys

On Friday 23 April 2004 2:05 pm, Jean-Baptiste Rouquier wrote:
> >With your specification (no repetitions in the list), that function
> >would run in quadratic time,
> Perhaps I'm all wrong, but when I have to get rid of repetitions in a
> list, I first sort it in O(n log n), then remove the repetitions in O(n).
> Jean-Baptiste.

I have no idea what I'm talking about, but does this function not do what you 
want in O(n):

let hashtbl_keys tbl =
  let rec helper k d l = match l with
    [] -> [k]
  | ok::t -> if k=ok then l else k::l
  Hashtbl.fold helper tbl []

because Hashtbl's iter and fold present duplicate keys subsequently?


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: