Version française
Home     About     Download     Resources     Contact us    
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: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] Specialized dictionaries

Marcin 'Qrczak' Kowalczyk writes:
 > 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 hashtbl.ml 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?

As  suggested  by  Xavier  regarding  your  other  question,  you  can
instantiate Hashtbl.Make accordingly:

======================================================================
module IntHashtbl = Hashtbl.Make(struct
  type t = int
  let equal = (==)
  let hash n = n land 0x3FFFFFFF
end)
======================================================================

To be  even more efficient, I'm  afraid you have to  follow your idea,
that is to inline this hash function in your own copy of hashtbl.ml.

-- 
Jean-Christophe Filliatre (http://www.lri.fr/~filliatr)

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr