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
[Caml-list] Specialized dictionaries
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Specialized dictionaries
> I need dictionaries indexed by ints which must be very fast. I'm
> afraid that there is an overhead in using Hashtbl.t such that the
> generic hash function must recognize that the value is immediate
> instead of using it as a hash directly.
> Is it worth to do something with it? What to do? I could copy the first
> half of and replace all occurrences of the function hash by
> land'ing with 0x3FFFFFFF (so the value is nonnegative and mod gives
> nonnegative results). Any better idea?

No, no need to copy anything, just unleash the power of functors!

module IntHashtbl = Hashtbl.make(struct type t = int
                                        let equal = (==)
                                        let hash x = x land 0x3FFFFFFF

I'm not sure the performance gain is significant, but it's worth a try.

- Xavier Leroy
Bug reports:  FAQ:
To unsubscribe, mail  Archives: