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
generic Hashtbl.to_array
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-07-26 (02:18)
From: oleg@p...
Subject: generic Hashtbl.to_array

I wonder about the following solution. At least it traverses the
hashtable exactly once (and it does not ignore the result of the

let to_array9 t =
  let Some (a,_) =
    Hashtbl.fold (fun k v seed ->
      match seed with
	Some (a,i) -> a.(i) <- (k,v); Some (a,i+1)
      | None -> let a =  Array.make (Hashtbl.length t) (k,v) in
                Some (a,1))
      t None
  in a