Skip to content

Commit

Permalink
fix: replace wrong examples with correct ones (#29282)
Browse files Browse the repository at this point in the history
The previous examples - 'Carla' and 'Carlos' were not hashed to 3. So, they are replaced with correct examples - 'Rama' and 'Sita'.
  • Loading branch information
Punith1117 authored Jan 4, 2025
1 parent 5bb2531 commit 64f5790
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion javascript/computer_science/project_hash_map.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if (index < 0 || index >= buckets.length) {

1. `set(key, value)` takes two arguments: the first is a key, and the second is a value that is assigned to this key. If a key already exists, then the old value is overwritten, and we can say that we *update* the key's value (e.g. `Carlos` is our key but it is called twice: once with value `I am the old value.`, and once with value `I am the new value.`. Following this logic, `Carlos` should contain only the latter value).

Recall that collisions occur when *TWO DIFFERENT* keys generate the same hash code and get assigned to the same bucket. (e.g. `Carlos` and `Carla` are both hashed to `3`, so `3` becomes a location for `Carlos` AND `Carla`. However, we know that this is not an update because the keys are different). Review the [dealing with collisions](https://www.theodinproject.com/lessons/javascript-hashmap-data-structure#collisions) section of the previous lesson to find a way to handle our collisions.
Recall that collisions occur when *TWO DIFFERENT* keys generate the same hash code and get assigned to the same bucket. (e.g. `Rama` and `Sita` are both hashed to `3`, so `3` becomes a location for `Rama` AND `Sita`. However, we know that this is not an update because the keys are different). Review the [dealing with collisions](https://www.theodinproject.com/lessons/javascript-hashmap-data-structure#collisions) section of the previous lesson to find a way to handle our collisions.

- Remember to grow your buckets to double their capacity when your hash map reaches the `load factor`. The methods mentioned later in this assignment can help you handle the growth logic, so you may want to implement this feature near the end. However, we mention this with `set()` because it's important to grow buckets exactly as they are being expanded.

Expand Down
2 changes: 1 addition & 1 deletion ruby/computer_science/project_hash_map.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ You already know the magic behind hash maps. Now it's time to write your own imp

1. `#set(key, value)` takes two arguments, the first is a key and the second is a value that is assigned to this key. If a key already exists, then the old value is overwritten or we can say that we *update* the key's value (e.g. `Carlos` is our key but it is called twice: once with value `I am the old value.`, and once with value `I am the new value.`. From the logic stated above, `Carlos` should contain only the latter value).
In the meantime, a collision is when *TWO DIFFERENT* keys sit inside the same bucket, because they generate the same hash code (e.g. `Carlos` and `Carla` are both hashed to `3`, so `3` becomes a location for `Carlos` AND `Carla`. However, we know that it is the collision. It means we should find a way how to resolve it — how to *deal with collisions*, which was mentioned in the previous lesson).
In the meantime, a collision is when *TWO DIFFERENT* keys sit inside the same bucket, because they generate the same hash code (e.g. `Rama` and `Sita` are both hashed to `3`, so `3` becomes a location for `Rama` AND `Sita`. However, we know that it is the collision. It means we should find a way how to resolve it — how to *deal with collisions*, which was mentioned in the previous lesson).
- Remember to grow your buckets size when it needs to, by calculating if your bucket has reached the `load factor`. Some of the methods in this assignment that are mentioned later could be reused to help you handle that growth logic more easily. So you may want to hold onto implementing your growing functionality just for now. However, the reason why we mention it with `#set` is because it's important to grow buckets exactly when they are being expanded.

Expand Down

0 comments on commit 64f5790

Please sign in to comment.