Skip to content

Use "key" instead of "value" in HashMap exercise #2763

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PaulXiCao
Copy link

No description provided.

Copy link

google-cla bot commented Jun 2, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@djmitche djmitche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What motivates this change? The objective is to count values, so it seems like 'value' is a good name.

It uses a std::collections::HashMap to keep track of which values have been seen and how many times each one has appeared.

@PaulXiCao
Copy link
Author

It is just that key/value have usually predefined meanings for hashmaps (associative containers in general). And as this is an exercise to for the API of hashmaps it might put some people off that the variable 'value' is used as a key.

Unsure if the proposed renaming is the best though. What about "values -> itemOccurences" and "value -> item"?

(Sorry about the formatting. I am on my phone atm.)

@djmitche
Copy link
Collaborator

djmitche commented Jun 3, 2025

I think a PR to change both the word used in the exercise and the variable name would be OK. itemOccurrences sounds pretty long, but item and items is probably OK!

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 this pull request may close these issues.

2 participants