哈希表/字典碰撞 [英] Hashtable/Dictionary collisions
问题描述
仅使用标准英文字母和下划线,最多可以使用多少个字符,而不会在散列表/字典中造成潜在的冲突。
Using the standard English letters and underscore only, how many characters can be used at a maximum without causing a potential collision in a hashtable/dictionary.
所以字符串:
blur
Blur
b
Blur_The_Shades_Slightly_With_A_Tint_Of_Blue
...
推荐答案
你不会在单个字母之间发生冲突。
There's no guarantee that you won't get a collision between single letters.
你可能不会,但是在 string.GetHashCode
未指定,可能会更改。 (特别是它在.NET 1.1和.NET 2.0之间发生变化,烧毁了假定它不会改变的人。)
You probably won't, but the algorithm used in string.GetHashCode
isn't specified, and could change. (In particular it changed between .NET 1.1 and .NET 2.0, which burned people who assumed it wouldn't change.)
请注意,哈希代码冲突不会停止精心设计的哈希表从工作 - 您仍然应该能够获得正确的价值观,如果他们有相同的哈希码,那么它可能需要使用相等的方式检查多个密钥。
Note that hash code collisions won't stop well-designed hashtables from working - you should still be able to get the right values out, it'll just potentially need to check more than one key using equality if they've got the same hash code.
任何依赖于哈希码唯一的字典都缺少有关哈希码的重要信息,IMO :)(除非它在 特定条件下运行,否则绝对知道它们将是独一无二的,即它使用完美散列函数。)
Any dictionary which relies on hash codes being unique is missing important information about hash codes, IMO :) (Unless it's operating under very specific conditions where it absolutely knows they'll be unique, i.e. it's using a perfect hash function.)
这篇关于哈希表/字典碰撞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!