From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA21515; Fri, 23 Aug 2002 18:27:20 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 SAA21376 for ; Fri, 23 Aug 2002 18:27:19 +0200 (MET DST) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g7NGRIv05940 for ; Fri, 23 Aug 2002 18:27:18 +0200 (MET DST) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id g7NGRIl74728 ; Fri, 23 Aug 2002 18:27:18 +0200 (CEST) Received: from localhost (douet@localhost) by clipper.ens.fr (8.12.3/jb-1.1) id g7NGRHL2013042 ; Fri, 23 Aug 2002 18:27:17 +0200 (MET DST) Date: Fri, 23 Aug 2002 18:27:17 +0200 (MET DST) From: Florian Douetteau Reply-To: Florian Douetteau To: sebastien FURIC cc: OCaml Mailing list Subject: Re: [Caml-list] Hashtbl.hash and Hashtbl.hash_param In-Reply-To: <3D665886.9CF7E626@tni.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT X-Virus-Scanned: by amavisd-milter (http://amavis.org/) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, 23 Aug 2002, sebastien FURIC wrote: After a quick inspection in the source byterun/hash.c, it appears that hash_param C implementation decrements a C static variable 'counter' whenever an object is considered and returns 0 whenever this counter reach 0 (that's a way to handle cycles). As a consequence (..details omitted..), in the case of the list type, if the length of your list is greater that the initial value of the counter, hash will always return 0. A quick fix is to use: hash_param 100 instead of hash (== hash_param 10 100) By the way, beware that hash_param is not thread-safe, since it uses a C global variable. -- Florian Douetteau > > > sebastien FURIC a écrit : > > > > What kind of algorithm is used to compute the hash code of objects in > > O'Caml ? > > > > Hashtbl.hash (List.map (fun x -> Random.int 100) > > [1;2;3;4;5;6;7;8;9;10]);; > > always returns 0 (Hashtbl.hash_param has the same properties) which is > > a poor result ! > > > > What can I do if I don't know the size of the list in advance ? > > Of course, I know I could use functors to specify my own hash function. > While prototyping I just would prefer an acceptable Hashtbl.hash > function to avoid writing "boring" code. > > Sebastien. > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners