caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Sparse structure
@ 2005-07-07 19:27 Chris King
       [not found] ` <1120765639.9384.42.camel@titania>
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Chris King @ 2005-07-07 19:27 UTC (permalink / raw)
  To: O'Caml Mailing List

I'm trying to create a sparse structure; i.e. a large structure which
doesn't allocate storage for "unused" fields.  Given a structure:

type foo = { a: int option; b: float option }

the best solution I can come up with, short of using Obj.magic, is to
use a hash table like this:

type foo_key = A_key | B_key
type foo_value = A_value of int | B_value of float
type sparse = (foo_key, foo_value) Hashtbl.t

which works, but the extra variant type required means more CPU time
and more keystrokes.  Is there a better solution than this?

The structure will have hundreds of fields, each with a different
type.  Most of the fields will be unused, but usage will be determined
at runtime so using objects is not an option.

Thanks!

- Chris K


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-07-08 23:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-07 19:27 Sparse structure Chris King
     [not found] ` <1120765639.9384.42.camel@titania>
2005-07-07 20:04   ` [Caml-list] " Chris King
     [not found] ` <87r7eamlv9.fsf@linux-france.org>
2005-07-07 20:16   ` Chris King
2005-07-08  0:57 ` Jacques Garrigue
2005-07-08 13:29   ` Chris King
2005-07-08 23:29     ` Jacques Garrigue

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).