comp.lang.ada
 help / color / mirror / Atom feed
From: Marius Amado Alves <amado.alves@netcabo.pt>
To: comp.lang.ada@ada-france.org
Subject: Re: Hashing on System.Address
Date: Tue, 14 Jun 2005 11:29:50 +0100
Date: 2005-06-14T11:29:50+01:00	[thread overview]
Message-ID: <mailman.28.1118745237.17633.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <200506141214.14213.baldrick@free.fr>


On 14 Jun 2005, at 11:14, Duncan Sands wrote:

> On Tuesday 14 June 2005 12:03, Marius Amado Alves wrote:
>>> ... The other thing I haven't really figured out is what to do
>>> if you have a 64-bit address, and Hash_Type is only 32...
>>
>> I gave a general solution to this class of cases before:
>>
>> <<
>> Treat both the input and output values as bit strings X (1 .. M) and Y
>> (1 .. N) respectively. (Use representation clauses, packed arrays, and
>> unchecked conversion for this.) Make N small, say 16. Set Y bits to 
>> the
>> value of X bits as follows:
>>
>> if M > N, Y (J) = X (1 + (J - 1) * M / N), for J in 1 .. N
>>
>> if M = N, Y = X
>>
>> if M < N, initialize Y to all zeros,
>>   then let Y (1 + (I - 1) * N / M) = X (I), for I in 1 .. M
>>>>
>
> Hi Marius, thanks for the suggestion.  A few comments though:
> if M > N (say M = 2*N) then you're skipping every second bit
> in X.  Why not use them - mix them in somehow?

Yes, I thought of that, namely picking every slice of M / N bits of the 
input and convert it to 1 bit. Example for M = 2 * N: 00 => 0, 01 => 0, 
10 => 1, 11 => 1. But see below.

>   If M < N then
> you are trying to spread the bits of X evenly throughout Y.  Are
> there any theoretical reasons to think this is a good strategy?

Intuition + experimentation. "Guess first, prove later" (Poincaré) I 
tested my function against GNAT's. Dispersion was equivalent. Speed 
also I if I remember correctly. That's proof enough for me. That's why 
I didn't advance to the slice variant just above.




  parent reply	other threads:[~2005-06-14 10:29 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-13 20:18 Hashing on System.Address Duncan Sands
2005-06-13 21:31 ` Mark Lorenzen
2005-06-14  7:23   ` Duncan Sands
2005-06-14 20:18     ` Randy Brukardt
2005-06-15  7:27       ` Duncan Sands
2005-06-13 21:57 ` Matthew Heaney
2005-06-13 23:41   ` Robert A Duff
2005-06-14  2:22     ` Matthew Heaney
2005-06-14  7:27       ` Duncan Sands
2005-06-14  8:52         ` Alex R. Mosteo
2005-06-14  9:06           ` Duncan Sands
2005-06-14  9:09           ` Duncan Sands
2005-06-14 17:00             ` Pascal Obry
2005-06-14 20:03             ` Randy Brukardt
2005-06-14 23:20               ` Robert A Duff
2005-06-15  7:13               ` Duncan Sands
2005-06-14  8:44       ` Larry Kilgallen
2005-06-14 10:03       ` Marius Amado Alves
     [not found]       ` <abb2a2c53e3708803aa68bb87834b7bc@netcabo.pt>
2005-06-14 10:14         ` Duncan Sands
     [not found]         ` <200506141214.14213.baldrick@free.fr>
2005-06-14 10:29           ` Marius Amado Alves [this message]
     [not found]           ` <64f19b6707e4d19f5362900bbfb80b76@netcabo.pt>
2005-06-14 10:49             ` Marius Amado Alves
2005-06-14  8:42     ` Larry Kilgallen
2005-06-14 11:18     ` Duncan Sands
2005-06-14  7:18   ` Duncan Sands
2005-06-14 15:18     ` Matthew Heaney
2005-06-14 16:22       ` Duncan Sands
replies disabled

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