最快的哈希码生成器.NET

Jad*_*ias 3 .net c# hash

我正在为C#中的System.Drawing.Point类实现自定义GetHashCode.我的方法目前无法满足以下要求:

var hashA = MyGetHashCode(new Point(1, 0));
var hashB = MyGetHashCode(new Point(0, 1));
var hashC = MyGetHashCode(new Point(0, 0));
var hashD = MyGetHashCode(new Point(1, 1));
Assert.AreNotEqual(hashA ^ hashB, hashC ^ hashD);
Run Code Online (Sandbox Code Playgroud)

要通过此测试,我确信使用新的SHA256Managed().ComputeHash(currentHash)可以.但是还有其他更快的哈希算法吗?我知道SHA256是关于安全性的,我不需要它.

Mar*_*ell 6

一个简单的哈希?怎么样的东西:

 (17 * point.X) + (23 * point.Y);
Run Code Online (Sandbox Code Playgroud)

或者更明显的熵:

int hash = -1047578147;
hash = (hash * -1521134295) + point.X;
hash = (hash * -1521134295) + point.Y;
Run Code Online (Sandbox Code Playgroud)

(来自C#的匿名类型代码的数字)