2016-05-14 08:34:57 -06:00
|
|
|
-- Ensure that that the element at i is in the right position,
|
|
|
|
-- and return a closure which can be used for continuing the sort.
|
2017-03-28 02:25:52 -06:00
|
|
|
local a= 'a b c'
|
|
|
|
local b ='12345678'
|
2017-04-25 00:23:03 -06:00
|
|
|
local x = 1.99e-07
|
2017-03-28 02:25:52 -06:00
|
|
|
local c = 'a b c' +'a b c'
|
|
|
|
local t = {
|
|
|
|
a = 1,
|
|
|
|
b =2 ,
|
|
|
|
c= 3,
|
|
|
|
}
|
2017-03-29 22:08:51 -06:00
|
|
|
if a~='a' then
|
|
|
|
local b=a
|
|
|
|
end
|
2017-03-28 02:25:52 -06:00
|
|
|
local e={a=1,b=2}
|
|
|
|
function aaa(a,b,c)
|
2017-03-29 22:08:51 -06:00
|
|
|
|
|
|
|
-- comment 1
|
|
|
|
-- comment 2 1231
|
|
|
|
-- comment 1 123 123 123123 12
|
|
|
|
-- [[ comment 1 ]]
|
|
|
|
--[[
|
|
|
|
muli comments
|
|
|
|
ssss
|
|
|
|
@asdasd sad
|
|
|
|
]]
|
|
|
|
local a = -1
|
|
|
|
return a+b-c
|
2017-03-28 02:25:52 -06:00
|
|
|
end
|
2017-03-29 22:08:51 -06:00
|
|
|
local b = {a=1,b=[[this is two space ;
|
|
|
|
]],c=2}
|
2017-03-28 02:25:52 -06:00
|
|
|
|
2016-05-14 08:34:57 -06:00
|
|
|
function quicksorter(i, vec, low, high)
|
|
|
|
if low >= high then
|
|
|
|
return quicksorter
|
|
|
|
else -- low < high
|
|
|
|
-- partition the vector and initialize the child closures
|
|
|
|
local middle = partition(vec, low, high)
|
|
|
|
local left, right = quicksorter
|
|
|
|
|
|
|
|
-- Create the promise
|
|
|
|
local function self(i, vec, low, high)
|
|
|
|
if i < middle then
|
|
|
|
left = left(i, vec, low, middle-1)
|
|
|
|
return self
|
|
|
|
elseif i > middle then
|
|
|
|
right = right(i, vec, middle+1, high)
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
end
|
2017-03-28 02:25:52 -06:00
|
|
|
|
2016-05-14 08:34:57 -06:00
|
|
|
-- Force the promise until i is in the right position
|
|
|
|
return self(i, vec, low, high)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function lazysort(vec, low, high)
|
|
|
|
local sorter = quicksorter
|
|
|
|
return function(i)
|
|
|
|
sorter = sorter(i, vec, low, high)
|
|
|
|
return vec[i]
|
|
|
|
end
|
|
|
|
end
|