Tag: 法哈希

为什么String GetHashCode只处理每四个字符?

我一直在阅读这篇文章,因为它是由Jon Skeet在这个答案上联系起来的。 我试图真正理解哈希是如何工作的,以及为什么乔恩喜欢他提供的算法。 我还没有声称对此有答案,但我确实有一个关于GetHashCode的基本System.String实现的具体问题。 考虑代码,重点是注释<<<<<==========行: public override unsafe int GetHashCode() { if (HashHelpers.s_UseRandomizedStringHashing) return string.InternalMarvin32HashString(this, this.Length, 0L); fixed (char* chPtr = this) { int num1 = 352654597; int num2 = num1; int* numPtr = (int*) chPtr; int length = this.Length; while (length > 2) { num1 = (num1 <> 27) ^ *numPtr; num2 = (num2 […]