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.
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).
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.
发布评论
评论(1)
处理值的顺序取决于解释器的排序算法。结果是你不应该担心它;无论它们以什么顺序处理,最终结果都是相同的(如果你对一副牌进行排序,无论你是否事先洗牌,只要
2 < 3< /code> 和
J
在除了最简单的排序算法之外的所有排序算法中,一个值在到达结果数组中的最终位置之前将被访问(“处理”)多次。当您在回调中
返回
时,您提供给uksort
,这不一定是最后一次为这两个值调用回调。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
andJ < Q
and so on).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 touksort
that is not necessarily the last time the callback will be called for those two values.