的String.GetHash code()在.NET中哈希的质量和稳定性?稳定性、质量、GetHash、String

2023-09-03 02:24:52 作者:花已落゛情已灭

我想知道在散质量和散稳定性的 String.GetHash code()在.NET实现?

I am wondering about the hash quality and the hash stability produced by the String.GetHashCode() implementation in .NET?

有关质量,我专注于算法方面(因此,哈希因为它影响大的哈希表,而不是出于安全顾虑的品质)。

Concerning the quality, I am focusing on algorithmic aspects (hence, the quality of the hash as it impacts large hash-tables, not for security concerns).

随后,有关稳定,我想了解一下可能出现从一个.NET版本下,潜在versionning问题。

Then, concerning the stability, I wondering about the potential versionning issues that might arise from one .NET version to the next.

在这两个方面的一些灯将是非常美联社preciated。

Some lights on those two aspects would be very appreciated.

推荐答案

我不能给你任何细节对品质的(虽然我认为这是因为字符串pretty的货物是该框架的核心课程之一这很可能是用作散列键)。

I can't give you any details about the quality (though I would assume it is pretty good given that string is one of the framework's core classes that is likely to be used as a hash key).

不过,对于稳定性,制作了不同版本的框架的哈希值code不能保证是相同的,它已改变了以往,因此你绝对不能依赖于散列code是稳定的版本之间(see这里一个参考,它改变了1.1和2.0 )之间。事实上,即使是32位和64位版本之间的不同的一样的框架版本; 从文档:

However, regarding the stability, the hash code produced on different versions of the framework is not guaranteed to be the same, and it has changed in the past, so you absolutely must not rely on the hash code being stable between versions (see here for a reference that it changed between 1.1 and 2.0). In fact, it even differs between the 32-bit and 64-bit versions of the same framework version; from the docs:

由GetHash code返回的值是与平台相关的。对于一个特定的字符串值,它不同于在32位和64位版本的.NET Framework。

The value returned by GetHashCode is platform-dependent. For a specific string value, it differs on the 32-bit and 64-bit versions of the .NET Framework.