Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HashMap Data Structure: Paragraph about overwriting values seems misplaced #27982

Closed
3 tasks done
gingkapls opened this issue May 15, 2024 · 2 comments · Fixed by #27999
Closed
3 tasks done

HashMap Data Structure: Paragraph about overwriting values seems misplaced #27982

gingkapls opened this issue May 15, 2024 · 2 comments · Fixed by #27999
Assignees

Comments

@gingkapls
Copy link
Contributor

Checks

Describe your suggestion

In the heading on buckets there is a paragraph that talks about overwriting values if the same item already exists in the hash table (with the same key and value).

What if we found the hash code, but also the key value is the same as what we already have in the bucket? We check if it’s the same item by comparing the keys, then we overwrite the value with our new value. This is how we can only have unique values inside a Set. A Set is similar to a hash map but the key difference (pun intended) is that a Set will have nodes with only keys and no values.

This paragraph comes right after the part that talks about retrieving values from the hashmap.

The paragraph is more relevant to the preceding part which talks about inserting values into the hashmap.

As it stands now, it's easy to mistake overwriting being a part of the retrieval function.

I think it would help with the flow of the section if we moved it to the part which talks about inserting values into the hashmap with some changes to the verbiage.

The section right now

Section with proposed changes

Path

Node / JS

Lesson Url

https://www.theodinproject.com/lessons/javascript-hashmap-data-structure

(Optional) Discord Name

ginned

(Optional) Additional Comments

No response

@CouchofTomato
Copy link
Member

Hey @JoshDevHub

Do you want to give your opinion on this one?

@JoshDevHub
Copy link
Contributor

Related to: #27174

I think the suggested changes are fairly good though, and I'd probably accept a PR for this.

One tweak I'd recommend is right here:

Now if we wanted to get a value using a key:

  1. Put each entry inside a bucket as a Node item, which holds both the key and the value.
  2. To retrieve the value, we hash the key and calculate its bucket number.

I think it's better to remove the first item in the list here. The get method for a hash map does nothing with setting up data -- it retrieves data that already exists.

Since you indicated you'd like to work on this, I'll assign you @gingkapls

Let me know if what I wrote above doesn't make sense or if you have any other questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants