caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Florian Douetteau <douet@clipper.ens.fr>
To: sebastien FURIC <sebastien.furic@tni-valiosys.com>
Cc: OCaml Mailing list <caml-list@inria.fr>
Subject: Re: [Caml-list] Hashtbl.hash and Hashtbl.hash_param
Date: Fri, 23 Aug 2002 18:27:17 +0200 (MET DST)	[thread overview]
Message-ID: <Pine.SOL.4.44.0208231806090.16104-100000@clipper.ens.fr> (raw)
In-Reply-To: <3D665886.9CF7E626@tni.fr>

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 <number_bigger_than_the_length_of_any_list> 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


  reply	other threads:[~2002-08-23 16:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-23 15:24 sebastien FURIC
2002-08-23 15:45 ` sebastien FURIC
2002-08-23 16:27   ` Florian Douetteau [this message]
2002-08-27  8:24 ` Xavier Leroy
2002-08-27  9:59   ` jeanmarc.eber
2002-08-27 10:58     ` Alain Frisch
2002-08-27 16:12   ` Blair Zajac

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=Pine.SOL.4.44.0208231806090.16104-100000@clipper.ens.fr \
    --to=douet@clipper.ens.fr \
    --cc=Florian.Douetteau@ens.fr \
    --cc=caml-list@inria.fr \
    --cc=sebastien.furic@tni-valiosys.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).