Browse thread
AW: [Caml-list] generic Hashtbl.to_array
- Christoph Bauer
[
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: | Christoph Bauer <christoph.bauer@l...> |
| Subject: | AW: [Caml-list] generic Hashtbl.to_array |
> > let to_array_4 t = > let init = ref None in > begin try Hashtbl.iter (fun k v -> init := Some (k,v); > raise Exit) t My guess: hashtbl has to loop over the first empty buckets. And this eats the cpu cycles. > with Exit -> () > end; > match !init with > | None -> [| |] > | Some i -> > let a = Array.make (Hashtbl.length t) i in > ignore (Hashtbl.fold (fun k v i -> a.(i) <- (k, v); i > + 1) t 0); > a Regards, Christoph Bauer