简体   繁体   English

uksort()如何在内部处理数组

[英]How does uksort() process an array internally

After working on this question for quite a while, I've realized that I don't fully understand how uksort works internally and can't find any documentation to that effect. 在解决了这个问题一段时间后,我意识到我不完全了解uksort在内部的工作方式,因此找不到任何相关文档。

What order are the values processed, and does further processing for a value stop when you return an integer value for the current comparison? 为当前比较返回整数值时,将按什么顺序处理值?对值的进一步处理会停止吗?

The order the values are processed in is up to the interpreter's sorting algorithm. 值的处理顺序取决于解释程序的排序算法。 The upshot is that you shouldn't worry about it; 结果是您不必为此担心。 the end result will be the same no matter what order they're processed in (if you sort of deck of cards it will end up in the same order whether or not you shuffled it beforehand as long as 2 < 3 and J < Q and so on). 不论处理顺序如何,最终结果都将相同(如果您按一副纸牌排序,则无论您是否事先将其洗牌(只要2 < 3J < Q和依此类推)。

In all but the most naïve sort algorithms a value will be visited ("processed") several times before arriving in its final place in the result array. 除了最幼稚的排序算法外,在到达结果数组的最后位置之前,将多次访问(“处理”)一个值。 When you return in the callback you supply to uksort that is not necessarily the last time the callback will be called for those two values. 当您return回调时,您将提供给uksort ,这不一定是最后一次针对这两个值调用回调的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM