Closed jramoyo closed 10 years ago
I should clarify in the documents that all of these collections require compare
, equals
, and hash
methods to be in agreement.
I understand equals
and hash
should be the same, but why should compare
affect these two?
Would you be able to suggest a work-around?
With a map, hash finds the general area, and equals distinguishes a value from others that have the same hash. With a sorted set, compare finds the general area, and equals finds the exact position relative to other values that are either equal or incomparable.
A sorted set does not lend itself well to indexing by one property and searching by another. You might consider keeping two sorted sets, one indexed by name, and the other by instrument.
Fair enough, thanks for the explanation.
I'm not a fan of commenting on dead issues... but this is a serious problem. The implementation doesn't work as documented. If it's required for the compare
callback to ALSO do all the checks that equals
does, because of the way it was implemented, then it needs to be documented.
I'm not a fan of commenting on dead issues... but this is a serious problem. The implementation doesn't work as documented. If it's required for the
compare
callback to ALSO do all the checks thatequals
does, because of the way it was implemented, then it needs to be documented.
I agree. Can you spare some time to propose a change?
I’m not entirely sure whether I’m still a maintainer here, but I can offer a review and inquire.
Cc @cdebost
I'm not a fan of commenting on dead issues... but this is a serious problem. The implementation doesn't work as documented. If it's required for the
compare
callback to ALSO do all the checks thatequals
does, because of the way it was implemented, then it needs to be documented.I agree. Can you spare some time to propose a change?
I’m not entirely sure whether I’m still a maintainer here, but I can offer a review and inquire.
I'll try to look at the underlying code soon, but I have a feeling that changing the implementation will dramatically reduce performance, since I'm guessing it first sorts everything, and then does deduplication in array order, requiring duplicates to be ordered next to each other in the underlying array, at least for initialization. Updating of documentation might be the quick route to somewhat solving this problem.
Yes, I believe documenting the invariants more thoroughly is the right way to go. Are you familiar with the companion documentation site http://www.collectionsjs.com/?
On Wed, Jun 17, 2020 at 9:46 AM Mark V notifications@github.com wrote:
I'm not a fan of commenting on dead issues... but this is a serious problem. The implementation doesn't work as documented. If it's required for the compare callback to ALSO do all the checks that equals does, because of the way it was implemented, then it needs to be documented.
I agree. Can you spare some time to propose a change?
I’m not entirely sure whether I’m still a maintainer here, but I can offer a review and inquire.
I'll try to look at the underlying code soon, but I have a feeling that changing the implementation will dramatically reduce performance, since I'm guessing it first sorts everything, and then does deduplication in array order, requiring duplicates to be ordered next to each other in the underlying array, at least for initialization. Updating of documentation might be the quick route to somewhat solving this problem.
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/montagejs/collections/issues/93#issuecomment-645489266, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAOXBWF5PMTTNH5EWXR4FTRXDXMXANCNFSM4AS3HE2A .
Yeah
Ok found the docs repo. I'll try and open an PR soon.
In the example below, elements in the set are identified as unique if the
name
fields are equal. Subsequently, they are sorted by theinstrument
field.It is expected for
SortedArraySet#find
to return the correct indexes corresponding to the names. However, starting index 2,find()
returns-1
.It appears that the
equals()
function is not getting called for all iterations (see log output below).This works if both
equals()
andcompare()
functions are referring to the same fields.Output