Re: Make sorting stable
| From: | Andrea Faulds | Date: | Wed, 04 Mar 2020 20:25:24 +0000 |
| Subject: | Re: Make sorting stable | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108856@lists.php.net to get a copy of this message | ||
Hi,
Larry Garfield wrote:
If I'm understanding the definition of stable here, it means that if two values evaluate to equal they will always end up in the same order in the output that they were in the input, yes? So (trivial example): $a = ["3", 2, 3, 5]; Sorts to: [2, "3", 3, 5]; always, whereas right now it may sort to that or to [2, 3, "3", 5], somewhat randomly. Am I understanding correctly?(That is _my_ understanding, though I'd take Nikita's word for it rather than mine.) I think you indirectly point out a good reason to have a stable sorting algorithm for PHP: PHP's weird type-juggling equality rules mean several kinds of values that are not really (===) equal will compare equal (==) so far as sorting cares, which probably means messy results sometimes when paired with an unstable sort? Thanks, Andrea