|
说明:
SetInteger(string key1,string key2,integer value)
SetReal(string key1,string key2,real value)
SetHandle(string key1,string key2,handle value)
实际上Handle和Integer的存储都是伪装的real储存,所以如果目录名和文件名都一样你储存handle再来次real或者integer就会被覆盖了。
CleanReal(string key)
清除目录名为key下的所有文件。
[jass]library HashCache
globals
integer array KEY_1
string array KEY_2
real array Value
integer array Next
integer array KEY_file
integer array KEY_file_Index
endglobals
function H2I takes handle h returns integer
return h
return 0
endfunction
function H2S takes handle valueHandle returns string
return I2S( H2I(valueHandle) )
endfunction
function ex_addr_string takes string s returns integer
return s
return 0
endfunction
function addr_string takes string s returns integer
return ex_addr_string(s)*3 + 10000
endfunction
function Add_String takes string key1,string key2,integer key returns nothing
local integer addr = addr_string(key1)
local integer x = addr
local integer index = 0
local integer step = 1
local boolean exit = false
set x = x - x/8192 * 8192
set index = x
loop
exitwhen exit == true
if x >= 8192 then
set x = x - 8192
endif
if KEY_file[x] == 0 then
set KEY_file[x] = addr
set KEY_file_Index[x] = key
exitwhen true
elseif KEY_file[x] == addr then
loop
exitwhen Next[index] == 0
set index = Next[index]
endloop
loop
if KEY_file[index+step] == 0 then
set KEY_file[index+step] = -1
set Next[index] = index + step
set KEY_file_Index[index+step] = key
set exit = true
exitwhen true
endif
set step = step + 1
endloop
else
set x = x + 1
set index = x
endif
endloop
endfunction
function SetReal takes string key1,string key2,real value returns nothing
local integer key = 0
local integer x = addr_string(key1)
local integer y = addr_string(key2)
set x = x - x/8192 * 8192
set y = y - y/8192 * 8192
loop
if y >= 8192 then
set y = y - 8192
endif
if KEY_2[y] == null then
set KEY_2[y] = key2
exitwhen true
elseif KEY_2[y] != key2 then
set y = y + 1
else
exitwhen true
endif
endloop
set key = x + y
loop
if key >= 8192 then
set key = key - 8192
endif
if KEY_1[key] == 0 then
set KEY_1[key] = addr_string(key1)
set Value[key] = value
call Add_String(key1,key2,key)
exitwhen true
elseif KEY_1[key] == addr_string(key1) then
set Value[key] = value
exitwhen true
else
set key = key + 1
endif
endloop
endfunction
function GetReal takes string key1,string key2 returns real
local integer x = addr_string(key1)
local integer y = addr_string(key2)
local integer key = 0
set x = x - x/8192 * 8192
set y = y - y/8192 * 8192
loop
if y >= 8192 then
set y = y - 8192
endif
if KEY_2[y] == key2 then
exitwhen true
else
set y = y + 1
endif
endloop
set key = x + y
loop
if key >= 8192 then
set key = key - 8192
endif
if KEY_1[key] == addr_string(key1) then
return Value[key]
else
set key = key + 1
endif
endloop
return 0.
endfunction
function CleanReal takes string key returns nothing
local integer addr = addr_string(key)
local integer x = addr
local integer temp = 0
local integer step = 0
set x = x - x/8192 * 8192
loop
exitwhen KEY_file[x] == addr
set x = x + 1
set step = step + 1
endloop
loop
exitwhen KEY_file_Index[x] == 0
set KEY_1[KEY_file_Index[x]] = 0
set Value[KEY_file_Index[x]] = 0
set KEY_file[x] = 0
set temp = x
set x = Next[x]
set KEY_file_Index[temp] = 0
set Next[temp] = 0
endloop
endfunction
function GetInteger takes string key1,string key2 returns integer
local integer i = R2I(GetReal(key1,key2))
return i
endfunction
function SetInteger takes string key1,string key2,integer value returns nothing
call SetReal(key1,key2,value)
endfunction
function SetHandle takes string key1,string key2,handle h returns nothing
call SetInteger(key1,key2,H2I(h))
endfunction
function GetUnit takes string key1,string key2 returns unit
return GetInteger(key1,key2)
return null
endfunction
function GetText takes string key1,string key2 returns texttag
return GetInteger(key1,key2)
return null
endfunction
function GetTimer takes string key1,string key2 returns timer
return GetInteger(key1,key2)
return null
endfunction
function GetLoc takes string key1,string key2 returns location
return GetInteger(key1,key2)
return null
endfunction
endlibrary
[/jass] |
评分
-
查看全部评分
|