caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Fergus Henderson <fjh@cs.mu.OZ.AU>
To: Chris Hecker <checker@d6.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] why does hashtbl not use lists?
Date: Tue, 10 Jul 2001 19:00:45 +1000	[thread overview]
Message-ID: <20010710190045.A15552@hg.cs.mu.oz.au> (raw)
In-Reply-To: <4.3.2.7.2.20010710013127.02c06600@shell16.ba.best.com>

On 10-Jul-2001, Chris Hecker <checker@d6.com> wrote:
> 
> Why does hashtbl.ml (from the standard library) use the bucketlist variant
> instead of just the built in lists with tuples?  Is there an efficiency thing
> going on here?

Yes.  I didn't write the code, but I'm sure that's the reason.
A list of pairs will use two two-word cells per list element,
whereas a bucketlist will use one three-word cell; as well as reducing
the amount of memory allocated, it also avoids an indirection.

P.S. We happen to use the same kind of trick in the Mercury standard library,
for lists of tokens in the Mercury lexer:

   % This "fat list" representation is more efficient than a list of pairs.
   :- type token_list      --->    token_cons(token, token_context, token_list)
                           ;       token_nil.

But note that we at least document why we do it! ;-)

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  reply	other threads:[~2001-07-10  9:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-10  8:34 Chris Hecker
2001-07-10  9:00 ` Fergus Henderson [this message]
2001-07-10  9:05 ` Jean-Christophe Filliatre
2001-07-10  9:42   ` Fergus Henderson
2001-07-10 14:44     ` Xavier Leroy
2001-07-10 17:04 Charles Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010710190045.A15552@hg.cs.mu.oz.au \
    --to=fjh@cs.mu.oz.au \
    --cc=caml-list@inria.fr \
    --cc=checker@d6.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).