On Tue, Sep 03, 2002 at 11:21:12AM +0300, Andrey Hristov wrote:
> So the docs are right?
> 
> Note that keys are preserved. array_unique() sorts the values treated as
> string at first, then will keep the first key encountered for every value,
> and ignore all following keys. It does not mean that the key of the first
> related value from the unsorted array will be kept.

They are right for current releases, but what is not said is that it's
not obvious what the order will be after sorting, so it's not really
useful to know that the first key for every value is kept. I would say
that the order now is undefined. I think it will be better with the new
code when there is a defined and concistent ordering, and I would say
it's backwards compatible since previously it wasn't defined.

As Melvyn just said in another post, mergesort would be nice since it's
stable, so I would like to see zend_mergesort() perhaps. It can be better
than qsort on small datasets, and some qsort() implementations use it
when the partition size is small enough. Some platforms have mergesort()
or msort().

In one way it might make sense to use the systems native sorting functions
when available, they are probably faster. OTOH it might lead to different
sorting on different platforms which is why I say that which key for a
value array_unique() keeps is undefined (except for new implementation).
I would expect mergesort functions to always be stable though, so it might
be safe to use native implementations.

Stig

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to