Uh oh!
There was an error while loading. Please reload this page.
Fix: combined hashcode conflict - #77
Conversation
ChebanovDD
commented
Apr 14, 2025
Hi @ikws4, |
ikws4
commented
Apr 15, 2025
intCombineHashCode(inthash1,inthash2){varhash=17;hash=hash*31+hash1;hash=hash*31+hash2;returnhash;}CombineHashCode(601853953,-523751028)// 953868668
CombineHashCode(-1082829219,161819752)// 953868668In my case, I have two viewmodels with different properties, but CombineHashCode merges them into the same hash code. Later, when accessing MemberInfo, it gets messed up. |
ChebanovDmitry
commented
Apr 16, 2025
Can you share the code from these two ViewModels here? Thanks. |
Sorry, I'm unable to provide those ViewModels because the HashCode changes each time it's compiled. It's very hard to reproduce, but I can confirm that the issue was resolved with this fix. |
ChebanovDD
commented
Apr 17, 2025
Yes, your solution solves the problem. But I think we can come up with a more performant solution that does not require additional memory allocation. Can you change the [MethodImpl(MethodImplOptions.AggressiveInlining)]publicstaticintCombineHashCode(inthash1,inthash2){varhash=(uint)hash1;hash^=(uint)hash2+0x9e3779b9+(hash<<6)+(hash>>2);return(int)hash;}If this solution works, you can modify your PR and I will merge it. Thanks 🙂 |
I asked Gemini to write a test for |
ChebanovDmitry
commented
Apr 17, 2025
I don't have access to your prompt |
ikws4
commented
Apr 17, 2025
Sorry, I've updated the link's permission. Would you please try again? |
There is no hash function with a fixed output size ( But in future versions, it might be worth thinking about changing the return type from |
No description provided.