|
//======================================2009.2.24再次优化精简代码=======================
//======================同时改为单链表,减少2个数组====================================== 2009.2.23 再次精简代码 减少了近一半代码量
代码说明:[jass]
SetDataInt 储存整数 SetDataReal 储存实数 SetDataString 储存字符串
例:call SetDataInt(整数A, 被绑定的handle类型数据B, 储存数据的名字c,要储存的整数d)
//A可以是任意数字(值被B覆盖);B,比如计时器,单位等;C要存的数据 名字叫什么;d 储存的数据。
//比如给单位udg_u 绑定数字174 名字叫"num" call SetDataInt(0,udg_u,"num",174)
// 实数 字符串的储存 获取 销毁 均以此类推
GetDataInt 储存整数 GetDataReal 储存实数 GetDataString 储存字符串
例:local integer i=GetDataInt(0,udg_u,"num")//取出前面存的那个174
DestroyDataInt 清除整数 DestroyDataReal 清除实数 DestroyDataString 清除字符串
例:call DestroyDataInt (0,udg_u,"num")//消除前面存的那个174[/jass]
全部代码如下:
[jass] //======================================2009.2.24再次优化精简代码=======================
//======================同时改为单链表,减少2个数组======================================
globals
handle D_H
integer D_I
integer Length=0
integer Last=0
integer array Last_Last
integer array Data_H
integer array Data_h
integer array Data_Next
integer array Data_Int
real array Data_Real
string array Data_String
boolean array Data_H_Int
boolean array Data_H_Real
boolean array Data_H_String
endglobals
constant function S2HI takes string i returns integer
return i
return 0
endfunction
constant function HI2S takes integer i returns string
return i
return null
endfunction
function SetData takes integer D_I,integer D_S returns integer
local integer Li=(D_I+D_S)-(D_I+D_S)/8191*8191
local boolean b=FALSE
set D_I=D_I-D_S
set D_S=Data_H[Li]
if D_S!=0 then
loop
if Data_h[D_S]==D_I then
return D_S
endif
exitwhen Data_Next[D_S]==0
set D_S=Data_Next[D_S]
endloop
set Li=D_S
set b=TRUE
endif
if Last!=0 then
set D_S=Last_Last[Last]
set Last_Last[Last]=0
set Last=Last-1
else
set D_S=Length+1
set Length=D_S
if Length>8191 then
return -174
endif
endif
if b then
set Data_Next[Li]=D_S
else
set Data_H[Li]=D_S
endif
set Data_h[D_S]=D_I
return D_S
endfunction
function SetDataInt takes integer D_I,handle D_H,string Name,integer Data returns nothing
set D_I=SetData(D_I,S2HI(Name))
if D_I!=-174 then
set Data_Int[D_I]=Data
set Data_H_Int[D_I]=TRUE
endif
endfunction
function SetDataReal takes integer D_I,handle D_H,string Name,real Data returns nothing
set D_I=SetData(D_I,S2HI(Name))
if D_I!=-174 then
set Data_Real[D_I]=Data
set Data_H_Real[D_I]=TRUE
endif
endfunction
function SetDataString takes integer D_I,handle D_H,string Name,string Data returns nothing
set D_I=SetData(D_I,S2HI(Name))
if D_I!=-174 then
set Data_String[D_I]=Data
set Data_H_String[D_I]=TRUE
endif
endfunction
function GetData takes integer D_I,integer D_S returns integer
local integer Li=(D_I+D_S)-(D_I+D_S)/8191*8191
set D_I=D_I-D_S
set D_S=Data_H[Li]
if D_S==0 then
return -174
else
loop
if Data_h[D_S]==D_I then
return D_S
endif
exitwhen Data_Next[D_S]==0
set D_S=Data_Next[D_S]
endloop
return -174
endif
endfunction
function GetDataInt takes integer D_I,handle D_H,string Name returns integer
set D_I=GetData(D_I,S2HI(Name))
if D_I!=-174 then
return Data_Int[D_I]
else
return 0
endif
endfunction
function GetDataReal takes integer D_I,handle D_H,string Name returns real
set D_I=GetData(D_I,S2HI(Name))
if D_I!=-174 then
return Data_Real[D_I]
else
return 0.
endif
endfunction
function GetDataString takes integer D_I,handle D_H,string Name returns string
set D_I=GetData(D_I,S2HI(Name))
if D_I!=-174 then
return Data_String[D_I]
else
return null
endif
endfunction
function DestroyData takes integer D_I,integer D_S returns integer
local integer Li=(D_I+D_S)-(D_I+D_S)/8191*8191
local integer h=D_I-D_S
local integer I=Data_H[Li]
if I==0 then
return -174
else
loop
exitwhen Data_h[I]==h
if Data_Next[I]==0 then
return -174
endif
set D_S=I
set I=Data_Next[I]
endloop
if Data_H_Int[I]==FALSE and Data_H_Real[I]==FALSE and Data_H_String[I]==FALSE then
set Last=Last+1
set Last_Last[Last]=I
set Data_h[I]=0
set D_I=Data_Next[I]
if Data_H[Li]==I then
if D_I!=0 then
set Data_H[Li]=D_I
else
set Data_H[Li]=0
endif
else
if D_I!=0 then
set Data_Next[D_S]=D_I
else
set Data_Next[D_S]=0
endif
endif
endif
return I
endif
endfunction
function DestroyDataInt takes integer D_I,handle D_H,string Name returns nothing
set D_I=DestroyData(D_I,S2HI(Name))
if D_I!=-174 then
set Data_H_Int[D_I]=FALSE
endif
endfunction
function DestroyDataReal takes integer D_I,handle D_H,string Name returns nothing
set D_I=DestroyData(D_I,S2HI(Name))
if D_I!=-174 then
set Data_H_Real[D_I]=FALSE
endif
endfunction
function DestroyDataString takes integer D_I,handle D_H,string Name returns nothing
set D_I=DestroyData(D_I,S2HI(Name))
if D_I!=-174 then
set Data_H_String[D_I]=FALSE
endif
endfunction
/////////////////////////////////////////////////////////////////////////////////[/jass] |
评分
-
查看全部评分
|