From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Hash Type Size Date: Mon, 19 Aug 2013 17:29:19 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <1679ec49-424b-43bd-8f35-a5f69e658112@googlegroups.com> <8e573dcd-e84d-423b-b319-d2224a1ce9ae@googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: loke.gir.dk 1376951361 22506 69.95.181.76 (19 Aug 2013 22:29:21 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Mon, 19 Aug 2013 22:29:21 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:16910 Date: 2013-08-19T17:29:19-05:00 List-Id: I said: ... > There's not much point anyway; you can't directly hash 32-bit signed > integers in a 32-bit hash value without resorting to Unchecked_Conversion, > and then you've already completely left the realm of safe and portable > (neither Integer nor Hash_Type has a defined size by the RM). I just remembered that you could use the 'Mod attribute function to do this conversion. But of course that doesn't depend on the size of the type of it's argument, so it will work on Integer (for instance) no matter what size Integer has. Doing so will eliminate the uppermost bits from the hash in some cases, but that's usually not a problem as values rarely get anywhere near as large as the maximum possible. (Hopefully, your types have ranges so you know for sure.) If you're actually using all 64-bits of an integer (and hopefully you are declaring that explicitly, so compilers that don't support it can reject it), then you'll have to use Unchecked_Conversion or streaming to convert it into something hashable. Which I still think is the best idea in 99% of the cases. Randy.