From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: RICCI Pierre <pricci@cenatoulouse.dgac.fr>, caml-list@inria.fr
Subject: Re: problem with Hashtbl.add function...
Date: Tue, 2 Mar 1999 11:35:40 +0100 [thread overview]
Message-ID: <19990302113540.19046@pauillac.inria.fr> (raw)
In-Reply-To: <36D69BA0.883EDADD@cenatls.cena.dgac.fr>; from RICCI Pierre on Fri, Feb 26, 1999 at 02:03:28PM +0100
> The result of the add command might give me a hashing table with a
> key=time and data=aircrafts with their position for each key.
> The problem is I obtain a hashing table where key=time but
> data=aircrafts with always the same position for each one.
Your code is too sketchy to understand what is wrong, but my guess is
that you're calling Hashtbl.add several times with the same
"aircraft" record, which you mutate in place. E.g.:
type aircraft = { mutable pos : int }
let a = { pos = 10 } in
Hashtbl.add tbl 1 a;
a.pos <- 20;
Hashtbl.add tbl 2 a
Both Hashtbl.find tbl 1 and Hashtbl.find tbl 2 will return {pos = 20},
since this is what you stored in the shared record a. What you wanted
is probably:
let a = { pos = 10 } in
Hashtbl.add tbl 1 a;
let a' = {a with pos = 20 } in
Hashtbl.add tbl 2 a'
> I think maybe it's the parameter "n" in (Hashtbl.hash_param n m x) which
> is too small,
No. The value of "n" may impact performance, but not semantics.
> Can anyone help me ?
My advice would be to make your type "aircraft" immutable, and write
your program without record assignment; it's much easier to
understand what is going on.
- Xavier Leroy
prev parent reply other threads:[~1999-03-02 12:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-02-26 13:03 RICCI Pierre
1999-03-02 10:35 ` Xavier Leroy [this message]
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=19990302113540.19046@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=caml-list@inria.fr \
--cc=pricci@cenatoulouse.dgac.fr \
/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