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