-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
HashCollisionLinearProbing will be unable to retrieve values after initial collision element is removed #23
Comments
I also found this problem. Is there a better solution |
I'll review the code and get back to you! Sorry for the delay! |
Hi, With the current approach of the algorithm, it is needed to add an else to search for possible deleted values. This is not the most optimized approach, and I'll review with more time and also provide a more optimized approach for this algorithm.
|
Hi,
Also added some tests with Mocha to make sure different scenarios were covered:
|
In Chapter 7 it seems like there is a serious issue with the way that LinearProbing has been implemented but it could be my lack of knowledge as I'm learning about these things for the first time with your book! In the example code from the book we get:
19 - Gandalf
29 - John
16 - Tyrion
16 - Aaron
13 - Donnie
13 - Ana
5 - Jonathan
5 - Jamie
5 - Sue
32 - Mindy
32 - Paul
10 - Nathan
**** Printing Hash ****
5 -> [Jonathan - jonathan@email.com]
6 -> [Jamie - jamie@email.com]
7 -> [Sue - sue@email.com]
10 -> [Nathan - nathan@email.com]
13 -> [Donnie - donnie@email.com]
14 -> [Ana - ana@email.com]
16 -> [Tyrion - tyrion@email.com]
17 -> [Aaron - aaron@email.com]
19 -> [Gandalf - gandalf@email.com]
29 -> [John - johnsnow@email.com]
32 -> [Mindy - mindy@email.com]
33 -> [Paul - paul@email.com]
If at this point we do the following:
hash.remove('Jonathan')
Now index 5 is assigned to undefined
console.log(hash.get('Jamie'))
we will get undefined because of line 44 which doesn't continue searching because the original table[position] returns undefined.
So it seems like any later entries that we created from a collision cannot be retrieved after the original key is removed.
The text was updated successfully, but these errors were encountered: