【发布时间】:2014-02-13 00:05:21
【问题描述】:
我尝试使用向量实现哈希表。我的表大小将在构造函数中定义,例如表大小为 31,要创建哈希表,我执行以下操作:
vector<string> entires; // it is filled with entries that I'll put into hash table;
vector<string> hashtable;
hashtable.resize(31);
for(int i=0;i<entries.size();i++){
int index=hashFunction(entries[i]);
// now I need to know whether I've already put an entry into hashtable[index] or not
}
有没有人可以帮助我,我该怎么做?
【问题讨论】:
-
这是你的真实代码吗?我可以发现至少 2 个错误(缺少右括号和您拼写错误的条目)
-
@Borgleader 不,我只是为了简化而写了其中的一部分。抱歉打错了
-
@TheGost 检查
hashtable[index].empty()?不过,我不明白您打算如何使用向量实现哈希表。对于哈希到同一索引的 2 个不同条目,您将如何处理? -
线性或二次探测?我没有显示那部分代码,请帮我问@Praetorian
-
呃,我评论的第一句话不就是这样吗?