Split the frozen pre-migration table module so value operations have a single authority in std-collections and GFM serialization stays in std-data. The split keeps every function body byte-identical and records the baseline value assertions; the public value-operation path moves from std:data/table to std:collections/table with no compatibility forwarder. Refs cflmy/marqdo#9, cflmy/marqdo-std-collections#1
3.5 KiB
@exec table
选择列
params(数据, 列)
列名 = table.columns(数据)
结果行 = []
行号 = 0
while 行号 < 长度(数据)
行 = table.row(数据, 行号)
结果行 = list.append(结果行, [行[列]])
行号 = 行号 + 1
end
return 表([列名[列]], 结果行)
过滤数值大于
params(数据, 列, 阈值)
列名 = table.columns(数据)
结果行 = []
行号 = 0
while 行号 < 长度(数据)
行 = table.row(数据, 行号)
if 行[列] > 阈值
结果行 = list.append(结果行, 行)
else
if true
忽略 = 0
end
end
行号 = 行号 + 1
end
return 表(列名, 结果行)
插入有序
params(已排序, 行, 列)
新列表 = []
已插入 = false
下标 = 0
while 下标 < 长度(已排序)
当前行 = 已排序[下标]
if not 已插入 and 当前行[列] > 行[列]
新列表 = list.append(新列表, 行)
新列表 = list.append(新列表, 当前行)
已插入 = true
else
if true
新列表 = list.append(新列表, 当前行)
end
end
下标 = 下标 + 1
end
if not 已插入
新列表 = list.append(新列表, 行)
else
if true
忽略 = 0
end
end
return 新列表
排序
params(数据, 列)
列名 = table.columns(数据)
行数 = 长度(数据)
已排序 = []
下标 = 0
while 下标 < 行数
已排序 = 插入有序(已排序, table.row(数据, 下标), 列)
下标 = 下标 + 1
end
return 表(列名, 已排序)
追加行
params(数据, 行)
列名 = table.columns(数据)
所有行 = []
行号 = 0
while 行号 < 长度(数据)
所有行 = list.append(所有行, table.row(数据, 行号))
行号 = 行号 + 1
end
return 表(列名, list.append(所有行, 行))
设置单元格
params(数据, 目标行, 目标列, 值)
列名 = table.columns(数据)
新行表 = []
行号 = 0
while 行号 < 长度(数据)
行 = table.row(数据, 行号)
if 行号 == 目标行
新行 = []
列号 = 0
while 列号 < 长度(行)
if 列号 == 目标列
新行 = list.append(新行, 值)
else
if true
新行 = list.append(新行, 行[列号])
end
end
列号 = 列号 + 1
end
新行表 = list.append(新行表, 新行)
else
if true
新行表 = list.append(新行表, 行)
end
end
行号 = 行号 + 1
end
return 表(列名, 新行表)
连接
params(左, 右, 左列, 右列)
表头 = list.concat(table.columns(左), table.columns(右))
结果行 = []
左行号 = 0
while 左行号 < 长度(左)
左行 = table.row(左, 左行号)
键 = 左行[左列]
右行号 = 0
while 右行号 < 长度(右)
右行 = table.row(右, 右行号)
if 右行[右列] == 键
结果行 = list.append(结果行, list.concat(左行, 右行))
else
if true
忽略 = 0
end
end
右行号 = 右行号 + 1
end
左行号 = 左行号 + 1
end
return 表(表头, 结果行)
分组
params(数据, 键列, 值列)
结果 = {}
行号 = 0
while 行号 < 长度(数据)
行 = table.row(数据, 行号)
键 = 行[键列]
当前 = map.get(结果, 键)
列表 = []
if map.has(结果, 键)
列表 = 当前
else
if true
忽略 = 0
end
end
列表 = list.append(列表, 行[值列])
结果 = map.set(结果, 键, 列表)
行号 = 行号 + 1
end
return 结果