Re: Re: qsort fix
| From: | Zeev Suraski | Date: | Fri, 28 May 1999 17:02:46 +0000 |
| Subject: | Re: Re: qsort fix | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-6177@lists.php.net to get a copy of this message | ||
I actually think it's legitimate. If your comparison function isn't
deterministic, the sorting algorithm may not make sense, and it
assumptions one makes when designing a sorting algorithm (at the very
least, that there's an order defined on the to-be-sorted set) end up not
being valid, and may screw the algorithm.
Zeev
On Fri, 28 May 1999, Rasmus Lerdorf wrote:
> > This is definitely a problem in Solaris's qsort(). The problem is
> > that we're really doing something that is kind of non-kosher.
> > Everybody else's qsort() seems to handly it fine, though.
>
> Since qsort() takes a user-supplied comparison function, the
> implementation should be robust enough to not crash regardless of what
> this comparison function returns. The Solaris man page for qsort just
> says:
>
> The function must return an integer less than, equal to, or
> greater than zero to indicate if the first argument is to be
> considered less than, equal to, or greater than the second
> argument.
>
> and then under the NOTES:
>
> The comparison function need not compare every byte, so
> arbitrary data may be contained in the elements in addition
> to the values being compared.
>
> The relative order in the output of two items that compare
> as equal is unpredictable.
>
>
> So, basically going from the first blurb there, they say, "if the first
> argument should be considered less than..." They don't say "if the first
> argument *is* less than..." which to me means that it should be valid to
> not use the same criteria on every iteration to determine which argument
> should be considered less than another. And they definitely don't
> explicitly say that the comparison function must always use the same
> criteria for comparing two values.
>
> Silly Sun...
>
> -Rasmus
>
>
> --
> PHP Development Mailing List http://www.php.net/
> To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
> For help: php-dev-help@lists.php.net
>
>
--
-----------------------------------------------------
Zeev Suraski <zeev@zend.com>
For a PGP public key, finger bourbon@netvision.net.il
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net