我不确定这个前缀哈希方法应该做什么?

时间:2011-12-06 03:13:18

标签: c++ hash collision-detection

前缀哈希函数用于什么?我创建了链接,二次和线性哈希表。我得到了简单,前缀和全长哈希方法,我不知道它们用于什么?

以下是代码:

int HashTable_qp::preHash(string & key, int tableSize )
{
    string pad = "AA";
    //some words in the input are less than 3 letters
    //I choose to pad the string with A because all padded characters 
    //have same ascii val, which is low, and will hopefully alter the results less
    if (key.length() < 3)
    {
        key.append(pad);
    }
    return ( key[0] + 27 * key[1] + 729 * key[2] ) % tableSize;
}

碰撞检测:

while(i != DataArray.size())
{
    tStart = clock();

    if(QuadraticProbingHT.preHash(DataArray[i],101) == QuadraticProbingHT.preHash(DataArray[i],101) )
    {
        collision_count++;
    }
    tStop = clock();
    total_c += tStop - tStart;
    i++;
}

1 个答案:

答案 0 :(得分:3)

前缀散列通过前几个字符(前缀)散列字符串。

请注意,在您给出的实现中,它使用前三个字符(如果存在;用必要时填充AA来哈希一个字符串)。因此,assassociate在此特定前缀哈希下具有相同的哈希值。

完整长度哈希使用字符串中的每个字符来确定哈希值。

相关问题