But what happens if I want to add an element with a key that is already in the hash table, but behind the sentry in the test path? Instead of overwriting the value of an instance with the same key that is already in the table, the add () method overwrites the sentinel.
add() should check every element after the watch (s) in the research path until it finds an empty element, as you indicated below. If he could not find a new element in the research path and there are sentinel elements on it, he can use the first sentinel slot to store the new element.
There is a hash table implementation at http://www.algolist.net/Data_structures/Hash_table/Open_addressing (HashMap.java). Its put() method does just that. (Collision resolution is linear sensing in the reference fragment, but I do not consider this an important difference from the point of view of the algorithm.)
After many deletion operations, the table may have too many sentinel elements. A solution for this would be to rebuild the hash table from time to time (i.e. rephrase everything) (depending on the number of elements and the number of sentinel elements). This operation will eliminate the elements of the sentinel device.
Another approach is to exclude the checkpoint element (DELETED) from the exploration path when you delete the element. In practice, in this case you have no controls in the table; There are only FREE and OCCUPIED slots. It can be expensive.
So, it seems that you need to look all the way to research for the key element that you need to insert before replacing the sentry element.
Yes it is. You must search until you find an empty item.
How is this problem handled in practice?
I donβt know too much about realistic hash table implementations in real life. I believe many of them are available on the Internet in open source projects. I just checked the Hashtable and HashMap classes in Java. Both use chaining instead of open addressing.
source share