是否有散列函数为任何长度相等的字符串提供唯一的散列?显然,对于有限的散列大小(例如32或64位),在该属性丢失之前,这将限制字符串长度。
基本上,我试图弄清楚是否可以进行字符串相等比较优化。
public bool Equals(FancyString other) {
// Reference and length equality checks ommitted...
if (Length <= MagicUniqueHashMaxLength && HashCode == other.HashCode)
return true; // since our hypothetical hash function is guaranteed to produce unique hashes up until X length
// Full character comparison ommitted as well...
}
有没有人知道具有此属性的哈希函数?