60c256f91b 2024-06-27 1: local s = {}
60c256f91b 2024-06-27 2: local 简文件库 = require("lfs")
60c256f91b 2024-06-27 3: local ffi = require("ffi")
60c256f91b 2024-06-27 4: --~ 排
60c256f91b 2024-06-27 5: --~ 办排中值的能
60c256f91b 2024-06-27 6: --~ 入参2
60c256f91b 2024-06-27 7: --~ 入参3
60c256f91b 2024-06-27 8: --~ 入参4
60c256f91b 2024-06-27 9: function s.历排(u1_0, u1, u2, u3, u4)
60c256f91b 2024-06-27 10: local h1_0
60c256f91b 2024-06-27 11: --~ 集排
60c256f91b 2024-06-27 12: h1_0 = {}
60c256f91b 2024-06-27 13: for u5 = 1, #u1_0 do
60c256f91b 2024-06-27 14: h1_0[#h1_0 + 1] = u1(u1_0[u5], u2, u3, u4)
60c256f91b 2024-06-27 15: end
60c256f91b 2024-06-27 16: return h1_0
60c256f91b 2024-06-27 17: end
60c256f91b 2024-06-27 18: --~ 文
60c256f91b 2024-06-27 19: --~ 历文的能
60c256f91b 2024-06-27 20: --~ 入参2
60c256f91b 2024-06-27 21: --~ 入参3
60c256f91b 2024-06-27 22: function s.历文(u1, u2, u3, u4)
60c256f91b 2024-06-27 23: local h1_0
60c256f91b 2024-06-27 24: --~ 集排
60c256f91b 2024-06-27 25: h1_0 = {}
60c256f91b 2024-06-27 26: for u5 in u2(u1, u3, u4) do
60c256f91b 2024-06-27 27: h1_0[#h1_0 + 1] = u5
60c256f91b 2024-06-27 28: end
60c256f91b 2024-06-27 29: return h1_0
60c256f91b 2024-06-27 30: end
60c256f91b 2024-06-27 31: --~ 排
60c256f91b 2024-06-27 32: --~ 能
60c256f91b 2024-06-27 33: function s.历排取一(u1_0, u1)
60c256f91b 2024-06-27 34: local h1
60c256f91b 2024-06-27 35: for u2 = 1, #u1_0 do
60c256f91b 2024-06-27 36: --~ 值
60c256f91b 2024-06-27 37: h1 = s.历排取一的模(h1, u1_0[u2], u1)
60c256f91b 2024-06-27 38: end
60c256f91b 2024-06-27 39: return h1
60c256f91b 2024-06-27 40: end
60c256f91b 2024-06-27 41: --~ 值
60c256f91b 2024-06-27 42: --~ 排中值
60c256f91b 2024-06-27 43: function s.历排取一的模(u1, u2, u3)
60c256f91b 2024-06-27 44: if u1 == nil then
60c256f91b 2024-06-27 45: return u2
60c256f91b 2024-06-27 46: elseif u3(u1, u2) then
60c256f91b 2024-06-27 47: return u2
60c256f91b 2024-06-27 48: else
60c256f91b 2024-06-27 49: return u1
60c256f91b 2024-06-27 50: end
60c256f91b 2024-06-27 51: end
60c256f91b 2024-06-27 52: --~ 对
60c256f91b 2024-06-27 53: --~ 能
60c256f91b 2024-06-27 54: function s.历对取一(u1_0, u1)
60c256f91b 2024-06-27 55: local h1, h2
60c256f91b 2024-06-27 56: for u2, u2_0 in pairs(u1_0) do
60c256f91b 2024-06-27 57: --~ 键
60c256f91b 2024-06-27 58: --~ 值
60c256f91b 2024-06-27 59: h1, h2 = s.历对取一的模(h1, h2, u2, u2_0, u1)
60c256f91b 2024-06-27 60: end
60c256f91b 2024-06-27 61: return h1, h2
60c256f91b 2024-06-27 62: end
60c256f91b 2024-06-27 63: function s.历对取一的模(u1, u2, u3, u4, u5)
60c256f91b 2024-06-27 64: if u1 == nil then
60c256f91b 2024-06-27 65: return u3, u4
60c256f91b 2024-06-27 66: elseif u5(u1, u2, u3, u4) then
60c256f91b 2024-06-27 67: return u3, u4
60c256f91b 2024-06-27 68: else
60c256f91b 2024-06-27 69: return u1, u2
60c256f91b 2024-06-27 70: end
60c256f91b 2024-06-27 71: end
60c256f91b 2024-06-27 72: function s.历对(u1_0, u1, u2)
60c256f91b 2024-06-27 73: local h1
60c256f91b 2024-06-27 74: local h1_0, h2_0
60c256f91b 2024-06-27 75: --~ 对
60c256f91b 2024-06-27 76: h1_0 = {}
60c256f91b 2024-06-27 77: for u3, u2_0 in pairs(u1_0) do
60c256f91b 2024-06-27 78: --~ 键
60c256f91b 2024-06-27 79: --~ 值
60c256f91b 2024-06-27 80: h1, h2_0 = u1(u3, u2_0, u2)
60c256f91b 2024-06-27 81: if h1 then
60c256f91b 2024-06-27 82: h1_0[h1] = h2_0
60c256f91b 2024-06-27 83: else
60c256f91b 2024-06-27 84: end
60c256f91b 2024-06-27 85: end
60c256f91b 2024-06-27 86: return h1_0
60c256f91b 2024-06-27 87: end
60c256f91b 2024-06-27 88: --~ 排中值
60c256f91b 2024-06-27 89: --~ 值类
60c256f91b 2024-06-27 90: --~ 办值的能
60c256f91b 2024-06-27 91: function s.操类(u1_0, u1, u2)
60c256f91b 2024-06-27 92: if type(u1_0) == u1 then
60c256f91b 2024-06-27 93: return u2(u1_0)
60c256f91b 2024-06-27 94: else
60c256f91b 2024-06-27 95: return u1_0
60c256f91b 2024-06-27 96: end
60c256f91b 2024-06-27 97: end
60c256f91b 2024-06-27 98: --~ 排中文
60c256f91b 2024-06-27 99: --~ 入参2
60c256f91b 2024-06-27 100: --~ 入参3
60c256f91b 2024-06-27 101: --~ 入参4
60c256f91b 2024-06-27 102: function s.全筛文(u1, u2, u3, u4)
60c256f91b 2024-06-27 103: print(4)
60c256f91b 2024-06-27 104: if string.find(u1, u2, u3, u4) then
60c256f91b 2024-06-27 105: return u1
60c256f91b 2024-06-27 106: end
60c256f91b 2024-06-27 107: end
60c256f91b 2024-06-27 108: --~ 文
60c256f91b 2024-06-27 109: --~ 前缀
60c256f91b 2024-06-27 110: function s.加前缀(u1, u2)
60c256f91b 2024-06-27 111: return (u2 or "") .. u1
60c256f91b 2024-06-27 112: end
60c256f91b 2024-06-27 113: --~ 文
60c256f91b 2024-06-27 114: --~ 后缀
60c256f91b 2024-06-27 115: function s.加后缀(u1, u2)
60c256f91b 2024-06-27 116: return u1 .. (u2 or "")
60c256f91b 2024-06-27 117: end
60c256f91b 2024-06-27 118: --~ 令
60c256f91b 2024-06-27 119: function s.办令(u1)
60c256f91b 2024-06-27 120: print(u1)
60c256f91b 2024-06-27 121: os.execute(u1)
60c256f91b 2024-06-27 122: end
60c256f91b 2024-06-27 123: --~ 文
60c256f91b 2024-06-27 124: --~ 前缀
60c256f91b 2024-06-27 125: function s.全筛前缀(u1, u2)
60c256f91b 2024-06-27 126: if string.sub(u1, 1, #u2) == u2 then
60c256f91b 2024-06-27 127: return u1
60c256f91b 2024-06-27 128: end
60c256f91b 2024-06-27 129: end
60c256f91b 2024-06-27 130: --~ 文
60c256f91b 2024-06-27 131: --~ 后缀
60c256f91b 2024-06-27 132: function s.全筛后缀(u1, u2)
60c256f91b 2024-06-27 133: if string.sub(u1, -#u2) == u2 then
60c256f91b 2024-06-27 134: return u1
60c256f91b 2024-06-27 135: end
60c256f91b 2024-06-27 136: end
60c256f91b 2024-06-27 137: --~ 目对
60c256f91b 2024-06-27 138: function s.用令行工具操文件(u1_0)
60c256f91b 2024-06-27 139: local k1_9
60c256f91b 2024-06-27 140: --~ 令行排
60c256f91b 2024-06-27 141: k1_9 = s.历文(u1_0.文件目, 简文件库.dir)
60c256f91b 2024-06-27 142: k1_9 = s.历排(k1_9, s.全筛后缀, u1_0.文件类)
60c256f91b 2024-06-27 143: for u1 = 1, #k1_9 do
60c256f91b 2024-06-27 144: k1_9[u1] = s.加前缀(k1_9[u1], u1_0.文件目)
60c256f91b 2024-06-27 145: k1_9[u1] = s.加前缀(k1_9[u1], [["]])
60c256f91b 2024-06-27 146: k1_9[u1] = s.加后缀(k1_9[u1], [["]])
60c256f91b 2024-06-27 147: k1_9[u1] = s.加前缀(k1_9[u1], u1_0.令行前缀)
60c256f91b 2024-06-27 148: s.办令(k1_9[u1])
60c256f91b 2024-06-27 149: end
60c256f91b 2024-06-27 150: end
60c256f91b 2024-06-27 151: --~ 文件路
60c256f91b 2024-06-27 152: --~ 式
60c256f91b 2024-06-27 153: function s.读文件(u1, u2)
60c256f91b 2024-06-27 154: local h1
60c256f91b 2024-06-27 155: local k1_3
60c256f91b 2024-06-27 156: --~ 文件
60c256f91b 2024-06-27 157: k1_3 = io.open(u1, u2 or "r")
60c256f91b 2024-06-27 158: --~ 文
60c256f91b 2024-06-27 159: h1 = k1_3:read("a")
60c256f91b 2024-06-27 160: k1_3:flush()
60c256f91b 2024-06-27 161: k1_3:close()
60c256f91b 2024-06-27 162: return h1
60c256f91b 2024-06-27 163: end
60c256f91b 2024-06-27 164: --~ 常量排
60c256f91b 2024-06-27 165: function s.加对限(u1_0)
60c256f91b 2024-06-27 166: table.insert(u1_0, 1, "local h1_0 = {}")
60c256f91b 2024-06-27 167: table.insert(u1_0, "return h1_0")
60c256f91b 2024-06-27 168: return table.concat(u1_0, "\n")
60c256f91b 2024-06-27 169: end
60c256f91b 2024-06-27 170: --~ 文
60c256f91b 2024-06-27 171: --~ 文件路
60c256f91b 2024-06-27 172: --~ 式
60c256f91b 2024-06-27 173: function s.写文件(u1, u2, u3)
60c256f91b 2024-06-27 174: local k1_3
60c256f91b 2024-06-27 175: --~ 文件
60c256f91b 2024-06-27 176: k1_3 = io.open(u2, u3 or "w")
60c256f91b 2024-06-27 177: k1_3:write(u1)
60c256f91b 2024-06-27 178: k1_3:flush()
60c256f91b 2024-06-27 179: k1_3:close()
60c256f91b 2024-06-27 180: end
60c256f91b 2024-06-27 181: --~ 文
60c256f91b 2024-06-27 182: function s.删左右空白(u1)
60c256f91b 2024-06-27 183: u1 = string.gsub(u1, "^%s+", "")
60c256f91b 2024-06-27 184: return string.gsub(u1, "%s+$", "")
60c256f91b 2024-06-27 185: end
60c256f91b 2024-06-27 186: --~ 对
60c256f91b 2024-06-27 187: --~ 对
60c256f91b 2024-06-27 188: function s.连两对(u1_0, u2_0)
60c256f91b 2024-06-27 189: for u3_0, u4_0 in pairs(u2_0) do
60c256f91b 2024-06-27 190: u1_0[u3_0] = u4_0
60c256f91b 2024-06-27 191: end
60c256f91b 2024-06-27 192: return u1_0
60c256f91b 2024-06-27 193: end
60c256f91b 2024-06-27 194: --~ 键
60c256f91b 2024-06-27 195: --~ 值
60c256f91b 2024-06-27 196: function s.修对类(u1_0, u2_0)
60c256f91b 2024-06-27 197: if tonumber(u1_0) then
60c256f91b 2024-06-27 198: return tonumber(u1_0), u2_0
60c256f91b 2024-06-27 199: else
60c256f91b 2024-06-27 200: return u1_0, u2_0
60c256f91b 2024-06-27 201: end
60c256f91b 2024-06-27 202: end
60c256f91b 2024-06-27 203: do
60c256f91b 2024-06-27 204: --~ 加数
60c256f91b 2024-06-27 205: local h1 = 0
60c256f91b 2024-06-27 206: function s.递增()
60c256f91b 2024-06-27 207: h1 = h1 + 1
60c256f91b 2024-06-27 208: return h1
60c256f91b 2024-06-27 209: end
60c256f91b 2024-06-27 210: end
60c256f91b 2024-06-27 211: --~ 左加数
60c256f91b 2024-06-27 212: --~ 右加数
60c256f91b 2024-06-27 213: function s.加法(u1, u2)
60c256f91b 2024-06-27 214: return u1 + u2
60c256f91b 2024-06-27 215: end
60c256f91b 2024-06-27 216: --~ 左减数
60c256f91b 2024-06-27 217: --~ 右减数
60c256f91b 2024-06-27 218: function s.减法(u1, u2)
60c256f91b 2024-06-27 219: return u1 - u2
60c256f91b 2024-06-27 220: end
60c256f91b 2024-06-27 221: --~ 左乘数
60c256f91b 2024-06-27 222: --~ 右乘数
60c256f91b 2024-06-27 223: function s.乘法(u1, u2)
60c256f91b 2024-06-27 224: return u1 * u2
60c256f91b 2024-06-27 225: end
60c256f91b 2024-06-27 226: --~ 左除数
60c256f91b 2024-06-27 227: --~ 右除数
60c256f91b 2024-06-27 228: function s.除法(u1, u2)
60c256f91b 2024-06-27 229: return u1 / u2
60c256f91b 2024-06-27 230: end
60c256f91b 2024-06-27 231: --~ 左数
60c256f91b 2024-06-27 232: --~ 右数
60c256f91b 2024-06-27 233: function s.位和(u1, u2)
60c256f91b 2024-06-27 234: return bit.band(u1, u2)
60c256f91b 2024-06-27 235: end
60c256f91b 2024-06-27 236: --~ 数
60c256f91b 2024-06-27 237: --~ 右移几位
60c256f91b 2024-06-27 238: function s.位右移(u1, u2)
60c256f91b 2024-06-27 239: return bit.rshift(u1, u2)
60c256f91b 2024-06-27 240: end
60c256f91b 2024-06-27 241: --~ 键
60c256f91b 2024-06-27 242: --~ 最大值
60c256f91b 2024-06-27 243: --~ 键
60c256f91b 2024-06-27 244: --~ 值
60c256f91b 2024-06-27 245: function s.筛对中最大值(u1, u2, u3, u4)
60c256f91b 2024-06-27 246: if u2 < u4 then
60c256f91b 2024-06-27 247: return true
60c256f91b 2024-06-27 248: end
60c256f91b 2024-06-27 249: end
60c256f91b 2024-06-27 250: --~ 最短键
60c256f91b 2024-06-27 251: --~ 值
60c256f91b 2024-06-27 252: --~ 键
60c256f91b 2024-06-27 253: --~ 值
60c256f91b 2024-06-27 254: function s.筛对中最短键(u1, u2, u3, u4)
60c256f91b 2024-06-27 255: if #u1 > #u3 then
60c256f91b 2024-06-27 256: return true
60c256f91b 2024-06-27 257: end
60c256f91b 2024-06-27 258: end
60c256f91b 2024-06-27 259: --~ 最短文
60c256f91b 2024-06-27 260: --~ 值
60c256f91b 2024-06-27 261: function s.筛排中最短文(u1, u2)
60c256f91b 2024-06-27 262: if #u1 > #u2 then
60c256f91b 2024-06-27 263: return true
60c256f91b 2024-06-27 264: end
60c256f91b 2024-06-27 265: end
60c256f91b 2024-06-27 266: --~ 内数
60c256f91b 2024-06-27 267: function s.to_uint64(u1)
60c256f91b 2024-06-27 268: local uint64_pointer = ffi.new("uint64_t[1]", u1)
60c256f91b 2024-06-27 269: return uint64_pointer[0]
60c256f91b 2024-06-27 270: end
60c256f91b 2024-06-27 271: --~ 键
60c256f91b 2024-06-27 272: --~ 值
60c256f91b 2024-06-27 273: --~ 要找的值
60c256f91b 2024-06-27 274: function s.全等筛对中值(u1, u2, u3)
60c256f91b 2024-06-27 275: if u2 == u3 then
60c256f91b 2024-06-27 276: return u1, u2
60c256f91b 2024-06-27 277: else
60c256f91b 2024-06-27 278: end
60c256f91b 2024-06-27 279: end
60c256f91b 2024-06-27 280: return s