Re: Re: qsort fix
| From: | Zeev Suraski | Date: | Fri, 28 May 1999 17:10:27 +0000 |
| Subject: | Re: Re: qsort fix | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-6180@lists.php.net to get a copy of this message | ||
On Fri, 28 May 1999, Rasmus Lerdorf wrote:
> > 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.
>
> Then that should be stated. Especially when all other implementations
> don't crash on this.
It actually may be luck rather than anything else. When your code screws
up it can end up undetected, and it can end up crashing. I think that
when a sorting function asks for a comparison function that compares two
elements, and should return 0 if they're equal, and a descriptive number
if they're not - it's pretty obvious it means it should be deterministic.
That's what comparison functions are, much like you wouldn't expect
operator< to return random information on you either if your operands are
identical.
Zeev
--
-----------------------------------------------------
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