开发者

Confusion about linear probe method based Open Addressing in hashtables?

Suppose array index according to hashing function for string "temp" is 155 and location 155 is pre-occupied then location 156 is tried. Suppose location 156 is available, so this entry is saved in location 156 instead of 155. L开发者_运维问答ater I find another string "another_temp", which maps to location 156. Again this is saved in next available location 157.

The question is : Later if I want to find out location of "another_temp", how I would know that it is 157 not 156, even though hash function returned 156?

Thanks.


You need to compare the key, not just the hash code. In a hash table, you anyway need to store the key ("temp" and "another_temp" in your case). It's not enough to just store and compare the hash value, because hash values are not unique.

There are a few problems with open addressing. One is: what to do after deleting an entry? Usually you store a special "deleted" marker. Another problem is: if there is a collision, should you increment the hash code? You will find more details in Wikipedia.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜