English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Sparse structure
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-07-07 (20:16)
From: Chris King <colanderman@g...>
Subject: Re: [Caml-list] Sparse structure
On 7/7/05, David MENTRE <dmentre@linux-france.org> wrote:
> Unless I haven't understood what you want to do, you don't need the
> foo_key type. The foo_value type already contains the key through the
> sum type.
> So I would use:
> type foo_value = A_value of int | B_value of float
> type sparse = (int (*or whatever is your key*), foo_value) Hashtbl.t

It's not foo_key I have a problem with (that's what I want), it's
foo_value I want to ditch.  I tried using only foo_value and Obj.tag
to generate hash keys based on the foo_value tag, which worked fine
for sticking data into the hash table but not so well for getting it
back out.

> Think also at the readability of your code. Except in very few
> situations, having maintainable code is more important that memory or
> CPU efficient code.

Memory is definitely an issue here; I'm going to have thousands of
these structures each with hundreds of unused fields.  CPU time is not
so much, which is why I'm leaning toward my initial solution, but
having to access structure fields like this:

(match Sparse.get A_key with A_value v -> v | _ -> assert false)

doesn't do much for readability (hence why I want to dump the foo_value type).

- Chris