henrylin03 / odin-hashmap

Implement hashmap data structure using vanilla JavaScript (Node) as part of The Odin Project's "Full Stack JavaScript" course.
MIT License
0 stars 0 forks source link

build `set` method to assign key/value pairs #1

Closed henrylin03 closed 1 month ago

henrylin03 commented 1 month ago

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

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.

henrylin03 commented 1 month ago

image this is the content that will assist with implementation - this has the steps in plain English

henrylin03 commented 1 month ago

as of 64adb0467339416e4e4cd347713465e7fc51a4f9, duplicate keys are already handled. however, we will complete #5 to handle collisions

we will close this when #5 is done

henrylin03 commented 1 month ago

as of #21, we now expand buckets every time we set an entry. this is now fixed.