Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] why does hashtbl not use lists?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-07-10 (09:00)
From: Fergus Henderson <fjh@c...>
Subject: Re: [Caml-list] why does hashtbl not use lists?
On 10-Jul-2001, Chris Hecker <> wrote:
> Why does (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 <>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.
Bug reports:  FAQ:
To unsubscribe, mail  Archives: