Version française
Home     About     Download     Resources     Contact us    
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,               tf@cip.physik.uni-muenchen.de              (o_
 Thomas Fischbacher -  http://www.cip.physik.uni-muenchen.de/~tf  //\
(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)