[Mono-dev] GetHashCode() implementation for class string

Евгений Гришуль eugeny.grishul at gmail.com
Sun Dec 7 23:25:25 EST 2008


I know about that violations and have never read their code. Mono
contributors can use Java version of hash code function. I just suggest
possible ways to solve problem =)
2008/12/8 Atsushi Eno <atsushi at ximian.com>

> Do NOT read MS BCL source code. Jack, now we will never accept your
> contributions to protect copyright violation possibly brought by you.
>
> It is EXPLICITLY written in our TOP page for contribution.
> http://mono-project.com/Contributing
>
> Atsushi Eno
>
> Jack wrote:
>
>> You can use Java version of hash code that loos like:
>>
>>        public static int JavaStringHashCode( string value )
>>        {
>>            int result = 0;
>>
>>            foreach( char character in value )
>>                result = 31 * result + character;
>>
>>            return result;
>>        }
>>
>> Also you can look into Microsoft's BCL sources to find appropriate
>> implementation.
>> WBR,
>> Eugeny Grishul
>>
>> On Mon, 08 Dec 2008 01:47:43 +0300, Alan McGovern <
>> alan.mcgovern at gmail.com> wrote:
>>
>>  On Mon, Dec 1, 2008 at 9:44 PM, CarGa <carga at mail.ru> wrote:
>>>
>>>  Hello, all!
>>>>
>>>> I was directed here by Atsushi Eno from mono-olive list with this
>>>> question/request about GetHashCode() method.
>>>>
>>>> DependencyProperty class (that lays at the very base of entire WWF and
>>>> WPF
>>>> libraries) heavily depends on quality of GetHashCode() method since we
>>>> use
>>>> it to find any particular DependencyProperty in some huge
>>>> Dictionary<int,
>>>> DependencyProperty> of others.
>>>>
>>>>
>>> If i understand correctly, you're using the hashcode fo a DP as a unique
>>> identifier. This is wrong. Hashcodes are by definition *not* a unique
>>> identifer and should not be used as such. You're completly misusing the
>>> hashcode in this case. Your code will never run correctly if you are
>>> using
>>> .GetHashCode() to supply the 'int' in Dictionary<int, DependencyProperty>
>>>
>>> Alan.
>>>
>>
>>
>>
>>
>


-- 
WBR,
Grishul Eugeny
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20081208/a996bd82/attachment.html 


More information about the Mono-devel-list mailing list