From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 0CF3ABCAE for ; Thu, 7 Jul 2005 22:16:46 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j67KGj4O009548 for ; Thu, 7 Jul 2005 22:16:45 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA17031 for ; Thu, 7 Jul 2005 22:16:45 +0200 (MET DST) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.199]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j67KGiki015528 for ; Thu, 7 Jul 2005 22:16:44 +0200 Received: by wproxy.gmail.com with SMTP id i28so284283wra for ; Thu, 07 Jul 2005 13:16:44 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=KNuDhj+xZr8Ad5YSPIS5dwiNC5QiPquMvgiPQdbg+sINKzccjlZj/dQKtTSOfhQ5jgDFog03pxru1XSfUhDDJwnz0jCQMp6qUguGxJ0VT1CB7Rl1o7TvieQjAReZNxzpHP1DQVsqoxMZ5jxVhg8PmZahv3oWnIb87f52wN5f3sg= Received: by 10.54.32.46 with SMTP id f46mr1055632wrf; Thu, 07 Jul 2005 13:16:44 -0700 (PDT) Received: by 10.54.5.77 with HTTP; Thu, 7 Jul 2005 13:16:43 -0700 (PDT) Message-ID: <875c7e070507071316460ea88@mail.gmail.com> Date: Thu, 7 Jul 2005 16:16:43 -0400 From: Chris King Reply-To: Chris King To: David MENTRE Subject: Re: [Caml-list] Sparse structure Cc: "O'Caml Mailing List" In-Reply-To: <87r7eamlv9.fsf@linux-france.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <875c7e0705070712273e4231a9@mail.gmail.com> <87r7eamlv9.fsf@linux-france.org> X-Miltered: at concorde with ID 42CD8DAD.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42CD8DAC.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 foo:01 foo:01 hashtbl:01 hash:01 hash:01 maintainable:98 wrote:01 sticking:01 assert:01 structures:01 int:01 int:01 data:02 match:02 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.2 X-Spam-Level: On 7/7/05, David MENTRE 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. >=20 > So I would use: > type foo_value =3D A_value of int | B_value of float > type sparse =3D (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 typ= e). - Chris