|
恩,前些天突然发现需要一个hash的基本系统,但是看到别人写的代码量太大了所以自己写了一个。
//===============================
integer array SYS_HashHandle
//===============================
function GetHandleIndexInHashTable takes handle h returns integer
local integer i = H2I(h)
local integer tmp = i
local integer c = 0
loop
exitwhen(c>2000)
set tmp = Mod(tmp*33,8191)//Mod是自己写的,取余数函数
if(SYS_HashHandle[tmp]==i)then
return tmp
endif
set c = c + 1
endloop
return -1
endfunction
function RemoveHandleFromHashTable takes integer i returns nothing
set SYS_HashHandle = 0
endfunction
function AddHandleToHashTable takes handle h returns integer
local integer i = H2I(h)
local integer tmp = i
local integer c = 0
loop
exitwhen(c>2000)
set tmp = Mod(tmp*33,8191)
if(SYS_HashHandle[tmp]==0)then
set SYS_HashHandle[tmp] = i
return tmp
endif
set c = c + 1
endloop
return -1
endfunction
//===========================
如上,代码量很少
使用经典的time33算法 |
评分
-
查看全部评分
|