-
Notifications
You must be signed in to change notification settings - Fork 757
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
Dictionary == operator produces unexpected behavior #2737
Comments
One possible solution we've found is to override the Dictionary == method as such:
This produces the expected behavior; there may be better implementations. |
Interesting. This is worth some discussion, and would be a significant API change, but I don't have any opinion yet. The only thing I'll say for now is that I would be happy to write a C++ primitive for any new method, because whatever SC implementation would be used would undoubtedly be very slow. |
Ouch ouch ouch! Discussion of API changes usually happens on the mailing list ( https://supercollider.github.io/community/mailing-lists.html ) -- maybe we can discuss the changes there? |
Should I get the ball rolling over on the SC mailing list (sc-devs I'm assuming)? |
The case is pretty uncontroversial, I'd expect, even if it is a breaking API change. If anyone has used The implementation, however, is something to debate. (think parent and proto envirs etc.)
this can be slow in some circumstances, so an extra primitive is a good idea. |
I would suggest checking the number of entries too before iterating. Also, I don't think there is a reason to iterate over both dictionary key-sets.
|
The implementation is trivial, and it should be in C++. Any SC implementation is likely to be an order of magnitude slower. Note that changing this would affect all of Dictionary's subclasses:
I've emailed the sc-dev list :) |
once the implementation for |
one more thing: anything that implements |
I puzzled over this for a minute, but it turns out it's a little deeper than that: checking the size appears to eliminate the need to iterate over both sides! That is, the potential failure case with looping over only one side is if the other side contains an entry not present in the side you looped through -- but in that case, the sizes will be different. |
@ekermit the message
For
|
I was about to report an issue with equality for Sets with objects that have a custom '==' method defined and I found this thread. The proposed solution ( #3011 ) seems to target Dictionary and its subclasses(?), whereas my issue may point to a bug in Dictionary's superclass - Set. It might be that I going about this the wrong way in general, in which case I hope to be enlightened. Not sure if I should make this a separate issue, so I adding it to this thread. Please let me know if you want me to make it a separate issue. I am getting unstable results comparing two Set objects containing objects of a class that defines its own equality '==' method. The results returns seemingly random true and false values. Here is a class I use for testing:
|
@blacksound Your object doesn't provide a Note from the docs (Object:-hash):
(There's a similar note on |
Thanks Brian, hash{
^this.instVarHash([\aa, \bb]);
} |
yes, that is the standard way to do it. Recently I noticed that the order should be encoded in |
@blacksound Yes, in fact you could simplify it to |
… for equality ( |
There seems to be an issue with the
==
operator with dictionaries: it only considers values (not key associations) for testing equality. Some MWEs that demonstrate the problem:It seems that Dictionary inherits the
==
operator from Collection, which relies on Dictionary's implementation ofincludes
, so whether it is appropriate to fixincludes
or override==
in Dictionary seems to me to be an open question. It's not immediately obvious whatincludes
should do - whether it operates on keys, values, or associations (i.e. a methodincludesValue
would clearly return true if the given value occurs in the dictionary, no matter what key it is associated with, butincludes
is more ambiguous.)There was some discussion of the appropriate behavior of set theory methods for dictionaries here but no discussion of the
==
operator there.The text was updated successfully, but these errors were encountered: