From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA15790 for caml-redistribution; Tue, 2 Mar 1999 13:32:40 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA08096 for ; Tue, 2 Mar 1999 11:35:46 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id LAA24053; Tue, 2 Mar 1999 11:35:40 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA08525; Tue, 2 Mar 1999 11:35:40 +0100 (MET) Message-ID: <19990302113540.19046@pauillac.inria.fr> Date: Tue, 2 Mar 1999 11:35:40 +0100 From: Xavier Leroy To: RICCI Pierre , caml-list@inria.fr Subject: Re: problem with Hashtbl.add function... References: <36D69BA0.883EDADD@cenatls.cena.dgac.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: <36D69BA0.883EDADD@cenatls.cena.dgac.fr>; from RICCI Pierre on Fri, Feb 26, 1999 at 02:03:28PM +0100 Sender: weis > 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