X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/8f26f83f38be36a6c73f4c1dfe1032a5b8fb2a17..1b909160d6588efc113fed329a9d6d7cff216e3a:/helpers.lua diff --git a/helpers.lua b/helpers.lua index b5b663d..fb71335 100644 --- a/helpers.lua +++ b/helpers.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ --]] @@ -10,6 +10,7 @@ local timer = require("gears.timer") local debug = require("debug") local io = { lines = io.lines, open = io.open } +local pairs = pairs local rawget = rawget local table = { sort = table.sort } @@ -179,6 +180,28 @@ function helpers.spairs(t) end end +-- create the partition of singletons of a given set +-- example: the trivial partition set of {a, b, c}, is {{a}, {b}, {c}} +function helpers.trivial_partition_set(set) + local ss = {} + for _,e in pairs(set) do + ss[#ss+1] = {e} + end + return ss +end + +-- creates the powerset of a given set +function helpers.powerset(s) + if not s then return {} end + local t = {{}} + for i = 1, #s do + for j = 1, #t do + t[#t+1] = {s[i],unpack(t[j])} + end + end + return t +end + -- }}} return helpers