Skip to content

Commit 7296deb

Browse files
committed
basic run
1 parent d1f3f97 commit 7296deb

File tree

10 files changed

+4418
-38
lines changed

10 files changed

+4418
-38
lines changed

resources/luajitCompact.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,19 @@ function defer(toBeClosed, callback)
2727
return result
2828
end
2929
end
30+
end
31+
32+
math.maxinteger = 0x7FFFFFFFLL
33+
function math.tointeger(x)
34+
if type(x) ~= "number" then
35+
return nil
36+
end
37+
38+
local int = x >= 0 and math.floor(x) or math.ceil(x)
39+
40+
if int == x then
41+
return int
42+
else
43+
return nil
44+
end
3045
end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
local byte = string.byte
2+
local max = 0x7fffffff
3+
local bit = require('bit')
4+
5+
---@class SDBMHash
6+
local mt = {}
7+
mt.__index = mt
8+
9+
mt.cache = nil
10+
11+
---@param str string
12+
---@return integer
13+
function mt:rawHash(str)
14+
local id = 0
15+
for i = 1, #str do
16+
local b = byte(str, i, i)
17+
id = id * 65599 + b
18+
end
19+
return bit.band(id, max)
20+
end
21+
22+
---@param str string
23+
---@return integer
24+
function mt:hash(str)
25+
local id = self:rawHash(str)
26+
local other = self.cache[id]
27+
if other == nil or str == other then
28+
self.cache[id] = str
29+
self.cache[str] = id
30+
return id
31+
else
32+
log.warn(('哈希碰撞:[%s] -> [%s]: [%d]'):format(str, other, id))
33+
for i = 1, max do
34+
local newId = (id + i) % max
35+
if not self.cache[newId] then
36+
self.cache[newId] = str
37+
self.cache[str] = newId
38+
return newId
39+
end
40+
end
41+
error(('哈希碰撞解决失败:[%s] -> [%s]: [%d]'):format(str, other, id))
42+
end
43+
end
44+
45+
function mt:setCache(t)
46+
self.cache = t
47+
end
48+
49+
function mt:getCache()
50+
return self.cache
51+
end
52+
53+
mt.__call = mt.hash
54+
55+
---@return SDBMHash
56+
return function()
57+
local self = setmetatable({
58+
cache = {}
59+
}, mt)
60+
return self
61+
end

resources/override_script/await.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ function m.close(id)
100100
if type(callback) == 'function' then
101101
xpcall(callback, log.error)
102102
end
103-
coroutine.close(co)
103+
-- luajit donot support coroutine.close
104+
-- coroutine.close(co)
104105
end
105106
end
106107
end

0 commit comments

Comments
 (0)