On Fri, Aug 1, 2008 at 7:08 AM, Matthew Toseland
<toad at amphibian.dyndns.org> wrote:
> On Thursday 10 July 2008 15:24, j16sdiz at freenetproject.org wrote:
>> Author: j16sdiz
>> Date: 2008-07-10 14:24:34 +0000 (Thu, 10 Jul 2008)
>> New Revision: 21030
>>
>> Modified:
>>    branches/saltedhashstore/freenet/src/freenet/support/BloomFilter.java
>> Log:
>> squeeze more hashes from SHA-256 for BloomFilter
>>
>> Modified:
> branches/saltedhashstore/freenet/src/freenet/support/BloomFilter.java
>> ===================================================================
>> --- branches/saltedhashstore/freenet/src/freenet/support/BloomFilter.java
> 2008-07-10 13:45:09 UTC (rev 21029)
>> +++ branches/saltedhashstore/freenet/src/freenet/support/BloomFilter.java
> 2008-07-10 14:24:34 UTC (rev 21030)
>> @@ -93,16 +93,16 @@
>>
>>               MessageDigest md = SHA256.getMessageDigest();
>>               try {
>> -                     ByteBuffer bf = null;
>> +                     byte[] lastDigest = key;
>> +                     ByteBuffer bf = ByteBuffer.wrap(lastDigest);
>>
>>                       for (int i = 0; i < k; i++) {
>> -                             if (bf == null || bf.remaining() < 8) {
>> -                                     md.update(key);
>> -                                     md.update((byte) i);
>> -                                     bf = ByteBuffer.wrap(md.digest());
>> +                             if (bf.remaining() < 4) {
>> +                                     lastDigest = md.digest(lastDigest);
>> +                                     bf = ByteBuffer.wrap(lastDigest);
>>                               }
>>
>> -                             hashes[i] = (int) ((bf.getLong() & 
>> Long.MAX_VALUE) % length);
>> +                             hashes[i] = (int) ((bf.getInt() & 
>> Long.MAX_VALUE) % length);
>
> Surely & Integer.MAX_VALUE ??

.. & Integer.MAX_VALUE remove the highest bit
this make sure the value is positive.

(btw, this code is removed in the latest version)

>
>>                       }
>>               } finally {
>>                       SHA256.returnMessageDigest(md);
>>
>> _______________________________________________
>> cvs mailing list
>> cvs at freenetproject.org
>> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
>>
>>
>
> _______________________________________________
> Devl mailing list
> Devl at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl
>

Reply via email to