Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating key that collides with deleted item causes dead items #42

Open
ghost opened this issue Nov 11, 2019 · 2 comments
Open

Updating key that collides with deleted item causes dead items #42

ghost opened this issue Nov 11, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Nov 11, 2019

Say A and B collide at attempt = 0. If we do the following

  • insert("A", <value of A>)
  • insert("B", <value of B>)
  • delete("A")
  • insert("B", <new value>)

The second B will be inserted where A used to be, at hash("B", n, 0), and the B at hash("B", n, 1) will become wasted space. Further, if we then call delete("B"), B will just be restored to its original value, rather than actually being deleted.

@Kle0s
Copy link

Kle0s commented Jan 24, 2020

absolutely right.
a simple (but fucking the complexity of the function) solution is to run through the items first, checking if there's an item with the key. if you find one, update the value and end the function call by return. otherwise, continue to adding a new item as shown in the tutorial.

@Lorilandly
Copy link

furthermore, when such a hash table is resized, the behavior is undefined.
If the dead B has a larger hash result, it will actually replace the new B in the resized hash table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants