从哈希表中删除条目的最佳方式 [英] Best way to remove an entry from a hash table
本文介绍了从哈希表中删除条目的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
一个简单的技巧是:
- 查找并删除所需的元素
- 转到下一个料斗
- 如果料斗为空,退出
- 如果存储桶已满,请删除该存储区中的元素,并使用常规方法将其重新添加到散列表中。在重新添加之前,必须删除该项目,因为可能会将该项目添加回其原始位置。
- 重复步骤2。
这种技术保持你的桌子整洁,减少了较慢的删除。
What is the best way to remove an entry from a hashtable that uses linear probing? One way to do this would be to use a flag to indicate deleted elements? Are there any ways better than this?
解决方案
An easy technique is to:
- Find and remove the desired element
- Go to the next bucket
- If the bucket is empty, quit
- If the bucket is full, delete the element in that bucket and re-add it to the hash table using the normal means. The item must be removed before re-adding, because it is likely that the item could be added back into its original spot.
- Repeat step 2.
This technique keeps your table tidy at the expense of slightly slower deletions.
这篇关于从哈希表中删除条目的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文