sorting - table.sort 使用什么算法?

标签 sorting lua lua-table

我很好奇 Lua 的默认算法是什么 table.sort使用,只是因为它比我遇到的其他一些排序算法慢。我也很好奇 Lua 的 table.sort是在引擎中用 C 编写的,或者如果它在 Lua 中的库中。

最佳答案

What algorithm does table.sort use?


comment in tablib.c (向上滚动一点)状态
/*
** {======================================================
** Quicksort
** (based on `Algorithms in MODULA-3', Robert Sedgewick;
**  Addison-Wesley, 1993.)
** =======================================================
*/
您可以在我提供的链接中阅读源代码。

I'm also curious if Lua's table.sort is written in the Engine in C, or if it's in a library in Lua.


此时,Lua 直接自带的所有库( iotablemath ,...)都是用 C 编写的。

关于sorting - table.sort 使用什么算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18043803/

相关文章:

c++ - 何时使用哪种排序算法,何时绝对不应该

random - Lua math.random 返回不稳定的值

memory-management - 有没有(简单的)方法来获取 Lua 表的内存使用情况?

c++ - 在 lua 中重新定义打印函数时遇到问题

arrays - 无法使用另一个表中的数字声明表元素

string - 如何根据另一个字符串表定义的顺序对一个字符串表进行排序(Lua)

c++ - 如何删除第一个数组的某个索引处的所有元素并且该索引取自第二个数组?

linux - Unix 逆序多列排序不起作用

c# - List<T> OrderBy 字母顺序

for-loop - string.match 在 Lua for 循环中不起作用