Re: Make sorting stable
| From: | Christoph M. Becker | Date: | Thu, 05 Mar 2020 14:11:11 +0000 |
| Subject: | Re: Make sorting stable | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108868@lists.php.net to get a copy of this message | ||
On 05.03.2020 at 13:05, Nikita Popov wrote:
>> Given that we have internal classes which deliberately have such
>> comparison behavior (i.e. returning 0 or 1, to signal that there is no
>> order defined), e.g. Closures[1], I tend to prefer raising a warning
>> instead of trying to recover.
>>
>> [1]
>>
>> <https://github.com/php/php-src/blob/php-7.4.3/Zend/zend_closures.c#L372ƒ‚5¥‚Ïic†“S¼
>> K>
>
> This is a different case. The problem with my example is that it reports
> equality where none exists, which is an issue if you try to change the
> ordering of equal elements. Your case (which is indeed somewhat common in
> extension code) always returns "greater-than" for non-equal elements. The
> end result here is that the sort will not have any defined order regardless
> of how we perform it. We can't really do anything about such cases.
Oops, of course. Thanks for clarifying! :)
> I expect that a proposal for userland compare and equality overloading may
> want to make the "not ordered" case more explicit, in which case we could
> throw a warning when such comparisons are performed as part of sorting.
ACK.
--
Christoph M. Becker