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: border1.nntp.dca3.giganews.com!border2.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!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, 2 Sep 2013 20:47:52 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <1679ec49-424b-43bd-8f35-a5f69e658112@googlegroups.com> <7aa26916-cde1-46f8-9f49-d9ebcc2dee93@googlegroups.com> <782ef090-7299-4164-b4e5-14a06d1c1a44@googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: loke.gir.dk 1378172873 8619 69.95.181.76 (3 Sep 2013 01:47:53 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 3 Sep 2013 01:47:53 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Original-Bytes: 3112 Xref: number.nntp.dca.giganews.com comp.lang.ada:183261 Date: 2013-09-02T20:47:52-05:00 List-Id: wrote in message news:782ef090-7299-4164-b4e5-14a06d1c1a44@googlegroups.com... >To be honest, this was mostly just laziness on my part; there is no good >(read: easy) >way to hash an opaque data type, and so a quick and dirty (and admittedly >non-ideal) way to simply use the pointer as the key itself. But this is a >lot tougher >to rationalize now that they are different sizes, so I guess the real >question is >"what's a good way to hash a private type/access value/system.address?" > >It would be nice if there was a interface exclusively for doing this; >something like >an 'Hash attribute that could be applied to any type to return either a >implementation-provided hash (like for strings) or that could be overridden >by >a programmer in fancier cases. You can already sort of hack it together >now using >Ada.Strings.Hash(T'Image(o)). We talked a bit about having some such thing, but the truth is that there isn't any obvious algorithm that would work well for all kinds of types. It would be very hard to write some sort of hash function that would work well on completely unknown data. We didn't think it was a good idea to make it easy to use a function that might not work on your actual data, as that would lead to piles of bug reports for implementers (and reports that they could not possibility do anything useful with). So my answer to "what's a good way to hash a private type/access value/system.address?" is that no such way exists. The best you can do is convert the data to a stream-element array and hash that somehow, but that most likely would be a dubious hash (there is a lot of unused bits in a typical record, and it would be really easy for those bits to end up being most of the result). The whole point is that a hash function needs to be tailored to the data that it is hashing. Randy.