Browse thread
Sparse structure
[
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: | Chris King <colanderman@g...> |
| Subject: | Sparse structure |
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