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