[Mono-dev] BitVector32 patch

Scott Peterson lunchtimemama at gmail.com
Tue Sep 9 19:09:52 EDT 2008


Sorry about the mixed objectives. I figured it was a short enough
patch that it would be easier to review all at once, rather than
sending two or three little patches to the list. Thanks for reviewing
it anyway, Rodrigo.


>> Index: class/System/System.Collections.Specialized/BitVector32.cs
>> ===================================================================
>> --- class/System/System.Collections.Specialized/BitVector32.cs  (revision
>> 111591)
>> +++ class/System/System.Collections.Specialized/BitVector32.cs  (working
>> copy)
>> @@ -84,14 +82,12 @@
>>
>>                        public override int GetHashCode ()
>>                        {
>> -                               return (((Int16) mask).GetHashCode () <<
>> 16) +
>> -                                      ((Int16) offset).GetHashCode ();
>> +                               return mask << offset;
>>                        }
>
> This change will reduce the entropy of the hash function.
> With your change the following sections will have the same hash code: (mask
> 1, offset 2), (mask 2, offset 1), (mask 4, offset 0).
> I believe the equivalent is something like (mask << 16) + offset. What do
> you think?
>

The value of mask will always be one less than a power of two (see
CreateSection for the implementation). So it could be 1 or 3 or 7, but
not 2 or 4. This means the hash will be unique for any two mask and
offset values.

>> @@ -218,7 +213,7 @@
>>                        StringBuilder b = new StringBuilder ();
>>                        b.Append ("BitVector32{");
>>                        long mask = (long) 0x80000000;
>> -                       while (mask > 0) {
>> +                       while (mask != 0) {
>>                                b.Append (((value.bits & mask) == 0) ? '0'
>> : '1');
>>                                mask >>= 1;
>>                        }
>>
>>
> I don't see the point of this change.
>

This is just a habit of mine. I might have put it in by mistake while
doing some other change which I got rid of. I can whack it.


More information about the Mono-devel-list mailing list