开放寻址与链式散列

时间:2015-09-03 18:57:36

标签: c++ hash

开放寻址通常比链式散列更快。我正在通过低负载系数(0.1)的成功研究来测试我的代码,但我不断获得链式散列而不是开放寻址的最佳时间结果。差异非常小,有时开放地址更快,但平均有100个插入时间,链接哈希的时间更好。

我使用vector<string>作为开放寻址的哈希表,并使用vector<list<string> >进行链式哈希和两者的通用哈希。

这是关于我正在计划的成功研究的代码的一部分:

链式哈希研究:

for (auto it_ric = this->hash[key].begin(); it_ric != this->hash[key].end(); it_ric++)
{
    if ((*it_ric) == string)
    {
        found = true;
    }
}

打开寻址:

while (found == false && key != hash.size())
{
    if (hash[key] == string)
    {
        key = hash.size();
        found = true;
    }
    else if (hash[key] == "")
    {
        key = hash.size();
        found = true;
    }
    else
    {
        key++;
    }
}

0 个答案:

没有答案