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.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Expand documentation of Set #45416
Expand documentation of Set #45416
Changes from 2 commits
55bbdd2
ed1b91d
b96715a
093176c
375fe43
f122d20
118b47f
aae98b1
38a8ff0
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really get the addition of
hash
here. You could have a set with a bunch of elements that all hash to1
, it would just be inefficient.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to prevent a user overloading
isequal
without overloadinghash
(e,g, having a bunch of not-equal elements that hash to1
is an implementation error). This is not legal according toisequal
docs though, so it might be redundant to also state it here. I'll remove it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, the problem is kind of the opposite, i.e., having multiple
isequal
elements with different hashes. So, omittinghash
may easily lead to hard-to-debug bugs, likeBtw,
hash
is usually mention for other languages too. Just to name few: C++, Rust, Java ... unless the set is BST-based, of course.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "and" doesn't seem quite accurate. I think it only calls
hash
, although that should always matchisequal
. Maybe we can just say that? The goal is always to agree withisequal
, but the mechanism ishash
. Making it sound like the mechanism isisequal
seems misleading.I think the logic is the same as
unique
, whose description does not mentionhash
, but (IMO) probably should. Mentioning that they agree, and linking tounique
here, might also be a good idea.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isequal
is actually called to checkhash
collisions forDict
(which implementsSet
internally) injulia/base/dict.jl
Line 273 in 0062c26
How about writing the assumption explicitly, like in Rust?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. So it does depend on both.
Maybe the description should first say what the contract is (unique according to
isequal
, just likeunique
) and later say that the fast implementation needshash
? Uniqueness in the 1st paragraph, what's efficient in the 2nd?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that really necessary for the docstring, though? To me, mentioning
hash
seem like an optimization based on the implementation detail of Set, and that is usually outside the scope of a docstring.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, yes! These two functions are entangled tightly. So, mentioning only one seems dangerous to me because it motivates the user to re-define
isequal
only, and it may lead to an incorrect/undefined behavior.