curriculum icon indicating copy to clipboard operation
curriculum copied to clipboard

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

Open lilyponds opened this issue 1 year ago • 10 comments

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.

lilyponds avatar Aug 21 '24 04:08 lilyponds

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?

JoshDevHub avatar Aug 21 '24 16:08 JoshDevHub

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.

lilyponds avatar Aug 21 '24 17:08 lilyponds

This issue is stale because it has had no activity for the last 30 days.

github-actions[bot] avatar Sep 21 '24 01:09 github-actions[bot]

@JoshDevHub Do you think any change is needed or can we close this out?

CouchofTomato avatar Sep 22 '24 20:09 CouchofTomato

This issue is stale because it has had no activity for the last 30 days.

github-actions[bot] avatar Oct 23 '24 02:10 github-actions[bot]

@JoshDevHub Can you take a look at this if you get time please

CouchofTomato avatar Oct 30 '24 12:10 CouchofTomato

This issue is stale because it has had no activity for the last 30 days.

github-actions[bot] avatar Nov 30 '24 02:11 github-actions[bot]

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)

hbar1st avatar Dec 07 '24 21:12 hbar1st

This issue is stale because it has had no activity for the last 30 days.

github-actions[bot] avatar Jan 08 '25 02:01 github-actions[bot]

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.

JoshDevHub avatar Sep 13 '25 16:09 JoshDevHub