Doc*_*own 23
不是很聪明,但足以满足大多数实际目的:
编辑:由于Henk Holterman的评论而改变,谢谢.
int hc=array.Length;
for(int i=0;i<array.Length;++i)
{
hc=unchecked(hc*314159 +array[i]);
}
return hc;
Run Code Online (Sandbox Code Playgroud)
如果你需要更复杂的东西,请看这里.
对于通常在 -1000 到 1000 之间的值数组,我可能会使用以下内容:
static int GetHashCode(int[] values)
{
int result = 0;
int shift = 0;
for (int i = 0; i < values.Length; i++)
{
shift = (shift + 11) % 21;
result ^= (values[i]+1024) << shift;
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19507 次 |
| 最近记录: |