TheOdinProject / curriculum

The open curriculum for learning web development
https://www.theodinproject.com/
Other
9.78k stars 13.14k forks source link

Ruby Course: Project HashMap - the hash method is incomplete. #28677

Open lilyponds opened 4 weeks ago

lilyponds commented 4 weeks ago

Checks

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. image

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.

JoshDevHub commented 4 weeks ago

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?

lilyponds commented 4 weeks ago

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.