c# - Hashcodes - multiply or xor? -
c# - Hashcodes - multiply or xor? -
i saw hash function - , triggered alarms:
public override int gethashcode() { var result = 0; unchecked { result = anintid.gethashcode(); result *= 397 * (astring != null ? astring.gethashcode() : 0); } homecoming result; }
my automated hash-code-smell-fixer-subroutine wants rewrite read:
public override int gethashcode() { var result = 0; unchecked { result = anintid.gethashcode() * 397; result = (result * 397) ^ (astring != null ? astring.gethashcode() : 0); } homecoming result; }
i can't remember learned pattern, seems of doesn't create sense:
the first multiplication 397 looks waste of time [redacted] {in brain minus coffee context, interpreted ^ exponentiation}does seem correct, or making mistakes?
c# gethashcode
Comments
Post a Comment