From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 61010BCAE for ; Thu, 7 Jul 2005 21:27:05 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j67JR5PD011694 for ; Thu, 7 Jul 2005 21:27:05 +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 VAA16462 for ; Thu, 7 Jul 2005 21:27:04 +0200 (MET DST) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.207]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j67JR34Y011687 for ; Thu, 7 Jul 2005 21:27:04 +0200 Received: by wproxy.gmail.com with SMTP id i28so274036wra for ; Thu, 07 Jul 2005 12:27:03 -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:mime-version:content-type:content-transfer-encoding:content-disposition; b=JaNSewngfBy6DzbF0BQn6+F2tX+NBCjB/RfDgRuBUyvqkIWLTTsm73m+mjhHH2IpOJYeXt5hB7rx0goAa73+Qn3mVrgvfzCPnU98O5qVS92XA97tAtlXXMF8djzGVf5+DEXTwS0fDN6+mqqpZyA1S4y32kts2mVGWY3SG/jCH8g= Received: by 10.54.24.38 with SMTP id 38mr1025221wrx; Thu, 07 Jul 2005 12:27:03 -0700 (PDT) Received: by 10.54.5.77 with HTTP; Thu, 7 Jul 2005 12:27:03 -0700 (PDT) Message-ID: <875c7e0705070712273e4231a9@mail.gmail.com> Date: Thu, 7 Jul 2005 15:27:03 -0400 From: Chris King Reply-To: Chris King To: "O'Caml Mailing List" Subject: Sparse structure Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Miltered: at nez-perce with ID 42CD8209.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42CD8207.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; foo:01 hash:01 foo:01 hashtbl:01 runtime:01 short:01 int:01 int:01 variant:02 objects:02 float:03 float:03 sparse:04 sparse:04 structure:04 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: 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 =3D { 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 =3D A_key | B_key type foo_value =3D A_value of int | B_value of float type sparse =3D (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