diff --git a/lib/gears/init.lua b/lib/gears/init.lua index fab5d1f5..6f5198d4 100644 --- a/lib/gears/init.lua +++ b/lib/gears/init.lua @@ -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"); diff --git a/lib/gears/sort.lua b/lib/gears/sort.lua deleted file mode 100644 index b8de9e49..00000000 --- a/lib/gears/sort.lua +++ /dev/null @@ -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 diff --git a/lib/wibox/drawable.lua b/lib/wibox/drawable.lua index cce23236..b3b6e2dc 100644 --- a/lib/wibox/drawable.lua +++ b/lib/wibox/drawable.lua @@ -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") diff --git a/lib/wibox/init.lua b/lib/wibox/init.lua index 74b7d99e..f7bdfdc9 100644 --- a/lib/wibox/init.lua +++ b/lib/wibox/init.lua @@ -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 diff --git a/spec/gears/sort_spec.lua b/spec/gears/sort_spec.lua deleted file mode 100644 index ca7e3491..00000000 --- a/spec/gears/sort_spec.lua +++ /dev/null @@ -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