Merge pull request #675 from psychon/remove-gears.sort

Remove gears.sort
This commit is contained in:
Daniel Hahler 2016-02-11 21:51:44 +01:00
commit 58954f7f08
5 changed files with 0 additions and 110 deletions

View file

@ -11,7 +11,6 @@ return
color = require("gears.color"); color = require("gears.color");
debug = require("gears.debug"); debug = require("gears.debug");
object = require("gears.object"); object = require("gears.object");
sort = require("gears.sort");
surface = require("gears.surface"); surface = require("gears.surface");
wallpaper = require("gears.wallpaper"); wallpaper = require("gears.wallpaper");
timer = require("gears.timer"); timer = require("gears.timer");

View file

@ -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

View file

@ -16,7 +16,6 @@ local beautiful = require("beautiful")
local cairo = require("lgi").cairo local cairo = require("lgi").cairo
local color = require("gears.color") local color = require("gears.color")
local object = require("gears.object") local object = require("gears.object")
local sort = require("gears.sort")
local surface = require("gears.surface") local surface = require("gears.surface")
local timer = require("gears.timer") local timer = require("gears.timer")
local matrix = require("gears.matrix") local matrix = require("gears.matrix")

View file

@ -17,7 +17,6 @@ local table = table
local string_format = string.format local string_format = string.format
local color = require("gears.color") local color = require("gears.color")
local object = require("gears.object") local object = require("gears.object")
local sort = require("gears.sort")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local surface = require("gears.surface") local surface = require("gears.surface")
local cairo = require("lgi").cairo local cairo = require("lgi").cairo

View file

@ -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