字符串哈希函数为长度相等但最长为X的字符串返回唯一哈希值?

时间:2017-06-23 18:20:21

标签: c# hash

是否有散列函数为任何长度相等的字符串提供唯一的散列?显然,对于有限的散列大小(例如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...
}

有没有人知道具有此属性的哈希函数?

0 个答案:

没有答案