caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: oleg@pobox.com
To: caml-list@inria.fr
Subject: generic Hashtbl.to_array
Date: Tue, 25 Jul 2006 19:16:15 -0700 (PDT)	[thread overview]
Message-ID: <20060726021615.4FF7DA9B1@Adric.metnet.fnmoc.navy.mil> (raw)


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


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
;;


             reply	other threads:[~2006-07-26  2:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-26  2:16 oleg [this message]
2006-07-26  9:48 ` [Caml-list] " Damien Doligez
  -- strict thread matches above, loose matches on Subject: below --
2006-07-25  8:29 Christoph Bauer

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=20060726021615.4FF7DA9B1@Adric.metnet.fnmoc.navy.mil \
    --to=oleg@pobox.com \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).