的String.GetHash code()在.NET中哈希的质量和稳定性? [英] Hash quality and stability of String.GetHashCode() in .NET?

查看:166
本文介绍了的String.GetHash code()在.NET中哈希的质量和稳定性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在散质量散稳定性 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是稳定的版本之间(<一href="http://blogs.msdn.com/ericlippert/archive/2005/10/24/do-not-use-string-hashes-for-security-purposes.aspx">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.

这篇关于的String.GetHash code()在.NET中哈希的质量和稳定性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆