Ruby Course: Project HashMap - the hash method is incomplete.
Checks
- [X] This is not a duplicate of an existing issue (please have a look through our open issues list to make sure)
- [X] I have thoroughly read and understand The Odin Project Contributing Guide
- [X] Would you like to work on this issue?
Describe your suggestion
In the HashMap project in the Ruby course, the hash method defined is incomplete, it converts a key by sending it to hash(key) and converts it to a hash_code, however for the exercise, what the method should be returning is hash_code%16, because the whole exercise as well as the previous lessons is driven off of assuming a size 16 array. If the desired action is for students do to the %16 within their own method, then we should instruct it, if we are suggesting them to use the currently stated hash method.
Path
Ruby / Rails
Lesson Url
https://www.theodinproject.com/lessons/ruby-hashmap
(Optional) Discord Name
No response
(Optional) Additional Comments
This is my first ever issue, I will try to follow your instructions but I am very much aware I can make some mistakes. I am on the "Using Git in the real world" lesson, and thought will take this opportunity to implement what I learn and also contribute to this great project and help someone's learning.
Hello @lilyponds thank you for making this issue, and congratulations on your first GitHub issue :tada:
hash_code % 16 isn't something we can do because it'd be inaccurate. The exact value to modulo with will change as the hash map grows.
So for example, when the hash map reaches a high "load factor", the hash map should be re-hashed into an array that's size 32, and that means you now have to modulo by 32 when hashing.
Does this make sense to you?
It does make total sense, the only thing I would add to this, would be a statement to make this clear in the exercise itself, that will allow the students to connect the dot from getting a really big number as an output of the hash method and converting it into something that is workable, and the conversion itself will be dependent on the number of items and load factor(triggering the size to go from 16>32). I might be trying to make this too instructional and if it is by choice that we want students to build this bridge themselves, that is okay, just wanted to share my outlook on this. Thank you for the response, appreciate it.
This issue is stale because it has had no activity for the last 30 days.
@JoshDevHub Do you think any change is needed or can we close this out?
This issue is stale because it has had no activity for the last 30 days.
@JoshDevHub Can you take a look at this if you get time please
This issue is stale because it has had no activity for the last 30 days.
hi guys, I hit a similar issue with the hash map exercise in the JS course. Should I open a separate issue for discussion or fill you all in here? (oh well, I'm already here so I'll just mention it and if needed, I'll repeat myself elsewhere if requested) Link to exercise: https://www.theodinproject.com/lessons/javascript-hashmap
In the paragraph below from the HashMap exercise, the way that the modulo is being referred to is suggesting that it is already part of the code but it is not.
However, there is one edge case our hash function still needs to address. For very long keys, our hash code will exceed the maximum integer value allowed by JavaScript. Once that happens, calculations become inaccurate, and the chance of collisions significantly increases. One way to avoid this issue is to apply the modulo % operator on each iteration instead of outside the loop at the end. This ensures the output never becomes larger than our bucket’s length.
In English if a sentence says "do so and so instead of -this other thing-" then it is normal to assume that the 2nd half "this other thing" has already been done (and the advice is being given to correct what was done). However, the code on the page does not have any modulo (within or without the for loop). So it does seem like the code is missing the final expression to turn the value of hashCode to something that fits within the capacity.
Apologies if this should have gone out into a different issue. (I will gladly open one if instructed)
This issue is stale because it has had no activity for the last 30 days.
Apologies it's taken me a while to look at this. I think we can put a statement in here for the hash() method section that states that makes sure people know to modulo the hash code by the capacity to get an index.
If you're still around and available to work on this, I'd be glad to give it to you to work on @lilyponds. If you don't want to work on it, feel free to let me know, and I can assign it to someone else.