我很好奇 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 直接自带的所有库(
io
, table
, math
,...)都是用 C 编写的。
关于sorting - table.sort 使用什么算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18043803/