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
Re: [Caml-list] possible to define a type where = is forbidden ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Thomas Fischbacher <Thomas.Fischbacher@P...>
Subject: Re: [Caml-list] EQ hash tables?

On Wed, 12 Oct 2005, Xavier Leroy wrote:

> Easily definable using the functorial interface to hash tables:
> module MyEqHashTable =
>   Hashtbl.Make(struct
>       type t = my_type_for_keys
>       let equal = (==)
>       let hash = Hashtbl.hash
>     end)
> > Of course, "EQ hash tables" have to be treated in a slightly special way
> > when talking about stop&copy GCing.
> No, not "of course".  You're thinking of using the address of a memory
> block as its hash value.  This indeed requires GC support.  But you
> can get the semantics you want (keys compared by reference) while
> still computing the hash code structurally.  This is what the code
> snippet above does.

Hm, okay. I agree that this does give me the same semantics.

But doesn't this degrade expected lookup performance to an O(n) list 
lookup if I put a lot of stuff into the hash which is (=) but not (==)?

regards,                   (o_
 Thomas Fischbacher -  //\
(lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y)           V_/_
(if (= x 0) y (g g (- x 1) (* x y)))) n 1))                  (Debian GNU)