comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Hash Type Size
Date: Mon, 2 Sep 2013 20:47:52 -0500
Date: 2013-09-02T20:47:52-05:00	[thread overview]
Message-ID: <l03f49$8db$1@loke.gir.dk> (raw)
In-Reply-To: 782ef090-7299-4164-b4e5-14a06d1c1a44@googlegroups.com

<sbelmont700@gmail.com> 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.





  reply	other threads:[~2013-09-03  1:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-18 21:05 Hash Type Size sbelmont700
2013-08-19  1:03 ` AdaMagica
2013-08-19 22:21   ` Randy Brukardt
2013-08-19 22:29     ` Randy Brukardt
2013-08-19 22:12 ` Randy Brukardt
2013-08-31  6:22   ` Peter Brooks
2013-08-31 15:57     ` sbelmont700
2013-09-03  1:47       ` Randy Brukardt [this message]
2013-09-03  2:31         ` Peter Brooks
2013-09-03 10:50           ` John B. Matthews
2013-09-03 17:18             ` Peter Brooks
2013-09-03 21:21               ` John B. Matthews
2013-09-04  4:50               ` Paul Rubin
2013-09-04  4:54                 ` Paul Rubin
2013-09-05 19:30                   ` John B. Matthews
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox