A modult a Modul:data tables/doc lapon tudod dokumentálni
local export = {}
local base_location = "Module:data tables"
local metadata = mw.loadData(base_location.."/metadata")
--"Module:data tables/data"
local shard_location_base = metadata
local shards = metadata
local tables = metadata
--[[
{"grc_RLBG_lemma_to_index",
"grc_RWoodhouse_lemma_to_headwords",
"grc_RWoodhouse_lemma_to_infinitives",
"la_RMA_index_to_phrases",
"grc_RCunliffe_lemma_to_index",
"la_RMA_lemmas_no_collision_to_ix_phrase" }
]]
function load_tables_unsharded()
function maybe_mw_load(x)
local success, val = pcall(function() return mw.loadData(x) end)
if success then return val else return nil end end
local unsharded, i = {}, 0
while #unsharded == i do
---shard_location_base
local val = maybe_mw_load(shard_location_base.."Unsharded"..tostring(i))
if val ~= nil then
unsharded = val end
i = i + 1
end
return unsharded
end
local unsharded = load_tables_unsharded()
function map(f, xs)
local ys = {}
for i,x in pairs(xs) do ys=f(x) end
return ys
end
function map_string(f, s)
local ys = {}
for i = 1,#s do ys=f(s:sub(i,i)) end
return ys
end
function fold(f, l, xs)
for i,x in pairs(xs) do l = f(l, x) end
return l
end
function hash(s)
return fold(
function(x,y) return x + y end,
0,
map_string(
function(x) return x:byte() end, s
)
)%shards
end
function export.list_tables()
return map(function (x) return x end, tables)
end
function export.load_table(n)
local t = {}
for i = 1,shards do
local curr = mw.loadData(shard_location_base..(i-1))
if curr ~= nil then
for k,v in pairs(curr) do
t=v end end end
for i,curr in pairs(unsharded) do
if curr ~= nil then
for k,v in pairs(curr) do
t=v end end end
return t
end
--[[
eventually:
1 : loop through all unsharded if multiple
2 : index k in unsharded and shard separately,
returning from unsharded preferentially ]]
function export.index_table(t, k)
local shard = mw.loadData(shard_location_base .. hash(k))
if unsharded ~= nil
and unsharded ~= nil
and unsharded ~= nil
then
return unsharded
else
if shard ~= nil then
return shard
else
return nil
end
end
end
function export.index_table_all(t, ks)
baskets, result = {}, {}
for i,k in pairs(ks) do
h = hash(k)
if baskets == nil then
baskets = {k}
else
baskets)+1] = k
end
end
for h,b in pairs(baskets) do
local shard = mw.loadData(shard_location_base..h)
for i,k in pairs(b) do
-- here, loop over all unsharded if multiple
if unsharded ~= nil
and unsharded ~= nil
and unsharded ~= nil
then
result = unshared
else
if shard ~= nil then
result = shard
end
end
end
end
return result
end
function export.select(t,p)
return nil --Not implemented.
end
return export