Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upRemove unnecessary condition in collision_resolution method #2131
Conversation
| @@ -47,7 +47,7 @@ def _set_value(self, key, data): | |||
| def _collision_resolution(self, key, data=None): | |||
| new_key = self.hash_function(key + 1) | |||
|
|
|||
| while self.values[new_key] is not None and self.values[new_key] != key: | |||
| while self.values[new_key] is not None: | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
marcoscannabrava
Jun 23, 2020
Author
Contributor
I might be wrong so I'd appreciate if you could explain it to me or point me to any link.
- How can a value be equal to a key? If it was, would it be a problem?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
marcoscannabrava
Jun 23, 2020
Author
Contributor
In this example d = {0: 0, 1: 1, 2: 2} if I want to insert a new value and the hashing function somehow returns key=2.
- Wouldn't we want to go into the loop to produce a new key so it doesn't collide with the key-value pair 2-2?
- It wouldn't anyway because "is not None" is sufficient condition, right?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
marcoscannabrava commentedJun 17, 2020
Describe your change:
Removed unnecessary condition in looping hash inside collision_resolution method.
Checklist:
Fixes: #{$ISSUE_NO}.