Remove gears.sort
It's unused since commit 0aa4304bda
. Before this was a stable sorting
algorithm since table.sort is allowed to be unstable. Apparently we don't need a
stable sorting algorithm anymore.
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
720768330c
commit
94e9a030c1
|
@ -11,7 +11,6 @@ return
|
|||
color = require("gears.color");
|
||||
debug = require("gears.debug");
|
||||
object = require("gears.object");
|
||||
sort = require("gears.sort");
|
||||
surface = require("gears.surface");
|
||||
wallpaper = require("gears.wallpaper");
|
||||
timer = require("gears.timer");
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
---------------------------------------------------------------------------
|
||||
-- @author Uli Schlachter
|
||||
-- @copyright 2010 Uli Schlachter
|
||||
-- @release @AWESOME_VERSION@
|
||||
-- @module gears.sort
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local ipairs = ipairs
|
||||
local table = table
|
||||
local error = error
|
||||
|
||||
local sort = { mt = {} }
|
||||
|
||||
local function less_than_comp(a, b)
|
||||
return a < b
|
||||
end
|
||||
|
||||
--- Sort a table. This interface should be identical to table.sort().
|
||||
-- The difference to table.sort() is that this sort is stable.
|
||||
-- @param list The table to sort (we do an in-place sort!).
|
||||
-- @param comp Comparator used for the sorting
|
||||
function sort.sort(list, comp)
|
||||
local comp = comp or less_than_comp
|
||||
|
||||
-- A table could contain non-integer keys which we have to ignore.
|
||||
local num = 0
|
||||
for k, v in ipairs(list) do
|
||||
num = num + 1
|
||||
end
|
||||
|
||||
if num <= 1 then
|
||||
-- Nothing to do
|
||||
return
|
||||
end
|
||||
|
||||
-- Sort until everything is sorted :)
|
||||
local sorted = false
|
||||
local n = num
|
||||
while not sorted do
|
||||
sorted = true
|
||||
for i = 1, n - 1 do
|
||||
-- Two equal elements won't be swapped -> we are stable
|
||||
if comp(list[i+1], list[i]) then
|
||||
local tmp = list[i]
|
||||
list[i] = list[i+1]
|
||||
list[i+1] = tmp
|
||||
|
||||
sorted = false
|
||||
end
|
||||
end
|
||||
-- The last element is now guaranteed to be in the right spot
|
||||
n = n - 1
|
||||
end
|
||||
end
|
||||
|
||||
function sort.mt:__call(...)
|
||||
return sort.sort(...)
|
||||
end
|
||||
|
||||
return setmetatable(sort, sort.mt)
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
|
@ -16,7 +16,6 @@ local beautiful = require("beautiful")
|
|||
local cairo = require("lgi").cairo
|
||||
local color = require("gears.color")
|
||||
local object = require("gears.object")
|
||||
local sort = require("gears.sort")
|
||||
local surface = require("gears.surface")
|
||||
local timer = require("gears.timer")
|
||||
local matrix = require("gears.matrix")
|
||||
|
|
|
@ -17,7 +17,6 @@ local table = table
|
|||
local string_format = string.format
|
||||
local color = require("gears.color")
|
||||
local object = require("gears.object")
|
||||
local sort = require("gears.sort")
|
||||
local beautiful = require("beautiful")
|
||||
local surface = require("gears.surface")
|
||||
local cairo = require("lgi").cairo
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
---------------------------------------------------------------------------
|
||||
-- @author Uli Schlachter
|
||||
-- @copyright 2014 Uli Schlachter
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local sort = require("gears.sort")
|
||||
|
||||
describe("gears.sort", function()
|
||||
local function test(expected, input)
|
||||
sort.sort(input)
|
||||
assert.are.same(expected, input)
|
||||
end
|
||||
|
||||
it("with empty input", function()
|
||||
test({}, {})
|
||||
end)
|
||||
|
||||
it("with sorted input", function()
|
||||
test({1, 2, 3, 4, 5, 6},
|
||||
{1, 2, 3, 4, 5, 6})
|
||||
end)
|
||||
|
||||
it("with reversed input", function()
|
||||
test({1, 2, 3, 4, 5, 6},
|
||||
{6, 5, 4, 3, 2, 1})
|
||||
end)
|
||||
|
||||
it("with repeating items", function()
|
||||
test({1, 2, 2, 3, 4, 4, 5},
|
||||
{1, 2, 2, 3, 4, 4, 5})
|
||||
end)
|
||||
|
||||
it("with repeating items and reversed input", function()
|
||||
test({1, 2, 2, 3, 4, 4, 5},
|
||||
{5, 4, 4, 3, 2, 2, 1})
|
||||
end)
|
||||
|
||||
it("with non-integer keys", function()
|
||||
test({2, 3, 4, Awesome = 42},
|
||||
{3, 4, 2, Awesome = 42})
|
||||
end)
|
||||
end)
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
Loading…
Reference in New Issue