From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id B68217F2AB for ; Fri, 21 Dec 2012 20:03:17 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of martin.jambon@ens-lyon.org) identity=pra; client-ip=66.111.4.28; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="martin.jambon@ens-lyon.org"; x-sender="martin.jambon@ens-lyon.org"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of martin.jambon@ens-lyon.org) identity=mailfrom; client-ip=66.111.4.28; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="martin.jambon@ens-lyon.org"; x-sender="martin.jambon@ens-lyon.org"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@out4-smtp.messagingengine.com) identity=helo; client-ip=66.111.4.28; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="martin.jambon@ens-lyon.org"; x-sender="postmaster@out4-smtp.messagingengine.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As4BAE6x1FBCbwQclGdsb2JhbABFg0iCcrdAFg4BAQEBBw0JCRQEI4IeAQEFIxUIOAEBDwsYAgIFFgsCAgkDAgECAUUGDQEHAQGID6JacINQjyEGgSKLNYMwgROIZZMUjXI X-IronPort-AV: E=Sophos;i="4.84,331,1355094000"; d="scan'208";a="187292715" Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 21 Dec 2012 20:03:16 +0100 Received: from compute5.internal (compute5.nyi.mail.srv.osa [10.202.2.45]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 464FA209BD; Fri, 21 Dec 2012 14:03:15 -0500 (EST) Received: from frontend1.nyi.mail.srv.osa ([10.202.2.160]) by compute5.internal (MEProxy); Fri, 21 Dec 2012 14:03:15 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=IAq2lPcGtH3E33Unt3gZUc tPfNA=; b=hkwHI+3JSYn+SWs0khHLpZXTdQZRrqWzCe2vFGwZyQIqI0pbVaHH6h 4UetRgIwvbldowfonnUuNPGIzSY/LQK2fWmS8L2ryVy7KETrhExvnsLcF3P5rNTd jf14x+NgKdNjIXXrxszMetPCSNjHmxrbvGtlru0Mbs8yqw4rbQfpI= X-Sasl-enc: gVLzadkM5ahFK1Ku84HYPEyFmUQYkyFmJYsjYWnnQ3Y/ 1356116595 Received: from [192.168.1.123] (unknown [50.76.32.210]) by mail.messagingengine.com (Postfix) with ESMTPA id C4BCF8E06F6; Fri, 21 Dec 2012 14:03:14 -0500 (EST) Message-ID: <50D4B271.7030209@ens-lyon.org> Date: Fri, 21 Dec 2012 11:03:13 -0800 From: Martin Jambon User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: Xavier Leroy CC: caml-list@inria.fr References: <50D433BE.4010309@inria.fr> In-Reply-To: <50D433BE.4010309@inria.fr> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Hashing failure On Fri 21 Dec 2012 02:02:38 AM PST, Xavier Leroy wrote: > On 12/20/2012 09:18 PM, Thomas Braibant wrote: > >> [Reducing a hash value to a [0, N) interval ] >> My question is : is there a safe way to bullet-proof my code against >> these pathological cases, without too much hinderance (this is some >> code whose efficiency is critical...) > > Some possibilities to reduce an integer k to the interval [0, N): > > abs (k mod N) > (if N > 0, k mod N is guaranteed to be in (-N,N) ) > > (k land max_int) mod N > ("land max_int" masks the sign bit off and preserves all other > bits, reducing k to [0, max_int]) Is the two's complement representation of integers guaranteed by all OCaml implementations? It would be helpful if the manual was explicit about it. Martin