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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 3084B7F75C for ; Wed, 10 Sep 2014 14:51:44 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=pra; client-ip=212.227.126.187; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=mailfrom; client-ip=212.227.126.187; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.kundenserver.de) identity=helo; client-ip=212.227.126.187; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="postmaster@mout.kundenserver.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuIBAAhJEFTU4367nGdsb2JhbABZg2BXyjKHUAGBDhYQAQEBAQEGDQkJFCqEAwEBBAFVJAULCxguVwYTCYgxDAmqLJM1AReJZIVDJgeETAWGGotgkjUFj1YcgV5qAYJOAQEB X-IPAS-Result: AuIBAAhJEFTU4367nGdsb2JhbABZg2BXyjKHUAGBDhYQAQEBAQEGDQkJFCqEAwEBBAFVJAULCxguVwYTCYgxDAmqLJM1AReJZIVDJgeETAWGGotgkjUFj1YcgV5qAYJOAQEB X-IronPort-AV: E=Sophos;i="5.04,499,1406584800"; d="asc'?scan'208";a="78442308" Received: from mout.kundenserver.de ([212.227.126.187]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 10 Sep 2014 14:51:41 +0200 Received: from office1.lan.sumadev.de (dslb-088-068-067-138.088.068.pools.vodafone-ip.de [88.68.67.138]) by mrelayeu.kundenserver.de (node=mreue001) with ESMTP (Nemesis) id 0Ld9iz-1YA8sO0Owr-00iQZn; Wed, 10 Sep 2014 14:51:41 +0200 Received: from [192.168.5.106] (dslb-088-068-067-138.088.068.pools.vodafone-ip.de [88.68.67.138]) by office1.lan.sumadev.de (Postfix) with ESMTPSA id 88D3BDC270; Wed, 10 Sep 2014 14:51:40 +0200 (CEST) Message-ID: <1410353499.3003.29.camel@thinkpad> From: Gerd Stolpmann To: Pippijn van Steenhoven Cc: caml-list@inria.fr Date: Wed, 10 Sep 2014 14:51:39 +0200 In-Reply-To: <20140910124101.GA30231@xinutec.org> References: <54101221.3010304@users.sourceforge.net> <1410348425.3003.11.camel@thinkpad> <1410351988.3003.19.camel@thinkpad> <20140910124101.GA30231@xinutec.org> Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-mycnptaT0dtsBUVy2U1b" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 X-Provags-ID: V02:K0:SyVC4vX0E/9hivReYKmOapnqIIPsQczukgTxUm1rOWH UIu01QNF4Pnpu25F7YTtfxIkuJvF16qA56iROqpBCzvB11SVdN KAtzsHjBbItBsdP6FC8IAmXJrQQdDPVcsgZcZykiYp/WSqUTW7 +dWmbS0qfyzFEeRx9gaMCfRyjufXpi370//Jy//gMr9X9pe8gC pZxr+t6EoPVqSnqSAG8BfZ2nL0OooJ6L66ptkUm+Az/OAO99hC fA4MJyiZmFclPZEHE6wUOiQisv7jWcOPRkvThqRucwOWaJop+k xLonqG7XEKlqaK18sRHQZaZ2BtRBXzEqNLFNdKKepXSB0VuQve vaAzDh23hHa3nwMwL1StVAJc+D21/3QbJM5PvQqLt X-UI-Out-Filterresults: notjunk:1; Subject: Re: [Caml-list] Clarification for the configuration of comparison functions --=-mycnptaT0dtsBUVy2U1b Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable Am Mittwoch, den 10.09.2014, 13:41 +0100 schrieb Pippijn van Steenhoven: > On Wed, Sep 10, 2014 at 02:26:28PM +0200, Gerd Stolpmann wrote: > > type t =3D ... > > type t_cmp =3D t * int > >=20 > > let wrap x =3D (x, Hashtbl.hash x) > >=20 > > let my_compare (x1,h1) (x2,h2) =3D > > if h1=3Dh2 then > > compare x1 x2 > > else > > h1-h2 >=20 > This code is incorrect when h1 is large and negative. Hashtbl.hash returns non-negative ints. For other hash functions you are correct. > You should use > "compare h1 h2" and annotate h1 and/or h2 with its type (int), so that > int-compare is called directly. >=20 > Also, if you store the hash before the actual value, compare will > probably stop comparing after it finds that the hashes are not equal, so > you can simply use the polymorphic compare on t_cmp. I don't know this > for sure, since I haven't looked at the source, but I would assume this > is true. The OCaml manual doesn't define compare for tuples, so you cannot exploit that. I wouldn't bet that compare runs from left to right over the values, as OCaml is known for sometimes preferring right to left. But maybe this could be a future language feature? If the OCaml manual defined compare on tuples, this would in deed be a fine trick. Gerd --=20 ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de My OCaml site: http://www.camlcity.org Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de ------------------------------------------------------------ --=-mycnptaT0dtsBUVy2U1b Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAABAgAGBQJUEElbAAoJEAaM4b9ZLB5TydQH/25ipHwzLlLTw11XwBFPhwn9 H/NDXnns3meAdBN0bU1v3YSfOpjFOCafJGaxx3w+eOe7A+HzByDyDckokYbxWYnb wEUyf5NwXLhFQRPDHzzMSbkxpO2VibZdmSiYA7NZayPoy1TEoZ0kwX1hZz+YEX6w SzDbZF51mtmsbm/TXPHNg5gL7hSXNkgMnywe3P5SY34k3xzaC3asU9TTr29tmj39 QnIsTLyHvkza89JbIv+2eg92INYaVsHChvjf57DoAiKyhM9K7Q2fv6XniSitzRSN fqZIPBOTRmejOMEshwKveNE3PfDt5Bmtcs9CKg0tSq0nAjJB0BgzYEeehVMLaI4= =NvD3 -----END PGP SIGNATURE----- --=-mycnptaT0dtsBUVy2U1b--