哪个排序算法不PHP的usort申请? [英] Which sort algorithms does PHP's usort apply?

查看:251
本文介绍了哪个排序算法不PHP的usort申请?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要排序修改时间升序和降序的文件。

I want to sort files by modification time ascending and descending.

根据这一回答它看起来像这样能最好地实现定义排序回调函数并使用usort / uasort。

According to this answer It looks like this can best be achieved defining a sort callback function and using usort/uasort.

不过,因为我的申请,我可能会碰到一些最坏的情况,对于一些排序算法的性质(例如几乎反向排序输入序列)。

However because of the nature of my application I am likely to run into some worst case scenarios for some sort algorithms (for example almost reverse-ordered input sequence).

由于每隔比较使用两个文件系统访问它们是在一定程度上的网络驱动器,比较的次数是非常关键的,并且必须减至最小。其他种类的迭代可以更

Because every comparison uses two file system accesses which are partly on network drives, the number of comparisons is critical and must be minimized. Other sorts of iterations can be more.

所以,不要PHP的数组排序功能,使用什么样的算法?快速排序? Multisort?有没有什么办法可以配置此?

So what sort algorithms do PHP's array sort functions utilise? Quicksort? Multisort? Is there any way I can configure this?

如果排序之前,我也许洗牌阵列?

Should I perhaps shuffle the array before sorting?

或者我需要写我自己的实现?

Or do I need to write my own implementation?

你知道吗,提供某种功能的可配置算法的一些好的库?

Do you know some good libraries that provide sort functions with configurable algorithms?

什么算法或方法来解决最小化的比较,你会推荐了这个问题?

What algorithm or ways to solve this problem of minimizing comparisons would you recommend?

推荐答案

php.net/sort 我发现这一点:

请注意:与大多数PHP的排序功能,排序()使用了»快速排序的实现

Note: Like most PHP sorting functions, sort() uses an implementation of » Quicksort.

<打击>我相信,它采用了随机快速排序的,所以没有必要洗牌数组

I believe that it uses a randomized quicksort, so there is no need for shuffling the array.

我也一些测试和PHP的快速排序是不是随机的,所以洗你的输入数组!!

I did some tests and PHP's quicksort is not randomized, so shuffle your input array!!

这篇关于哪个排序算法不PHP的usort申请?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆