From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pB67MlnV016744 for ; Tue, 6 Dec 2011 08:22:47 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: At4AAMDB3U7RVdI2kGdsb2JhbABEqj8IIgEBAQEJCQ0HFAQhggsCExkBEicDDQUQXRIBBQEWDDWcW4JcCo5PhRKJLgIFCosaBJRejWg9gUuCLQ X-IronPort-AV: E=Sophos;i="4.71,304,1320620400"; d="scan'208";a="122176375" Received: from mail-pz0-f54.google.com ([209.85.210.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 06 Dec 2011 08:22:41 +0100 Received: by dakp5 with SMTP id p5so3167636dak.27 for ; Mon, 05 Dec 2011 23:22:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=d1tqrvLaJuk1CxQBIkh+U9sAaBw/yvXe+GY7xPVozrs=; b=kSFiOZJTGiGKmbe14ZrRL8KcO/QqqnAOx0bmhTYAYaGaiMXH4mdSVBS+BWuVSZvtnQ 0vPsYinHz3EVKArh9ztgMGT2aGEEfURW7fSGzcA6mPIc6QsamhImSydzHjYl+Mv28DMc rnA64s2x4lH/lgGNLdFs5T9nDqqnGUpAyEb8s= MIME-Version: 1.0 Received: by 10.68.36.73 with SMTP id o9mr30739185pbj.82.1323156159978; Mon, 05 Dec 2011 23:22:39 -0800 (PST) Sender: damien.pous@gmail.com Received: by 10.142.76.5 with HTTP; Mon, 5 Dec 2011 23:22:39 -0800 (PST) Date: Tue, 6 Dec 2011 08:22:39 +0100 X-Google-Sender-Auth: ivh90DF6if7YINRLNuutLVe3gGU Message-ID: From: Damien Pous To: caml-list Content-Type: text/plain; charset=ISO-8859-1 Subject: [Caml-list] hashing big ints Dear caml-list, Let me re-raise an apparently old and possibly dumb question : how to hash big ints ? Hashtbl.hash doesn't work (ocaml 3.12.1): # Hashtbl.hash (Big_int.big_int_of_int 42);; - : int = 1 # Hashtbl.hash (Big_int.big_int_of_int 33);; - : int = 1 (Certainly because big ints hide their content in custom blocks.) I found several discussions about this kind of problem (comparison of nums, etc...), which were more focused on how to let Pervasive.compare/equal and Hashtbl.hash behave correctly in a uniform way. My question is simpler : I just need to write my own hashing function, so that I can call Hashtbl.Make. I currently use something like: let rec hash x = try int_of_big_int x with _ -> hash (shift_right_big_int x Sys.word_size) Some of you certainly know how to get a better behaved function. (I don't know anything about hashing theory, except that my function is certainly not a good one: it doesn't contain any prime number...) Thanks for your help, Damien