| 03-02-2007, 05:07 PM | #1 |
kay i have a long list like below : JASS:
if id=='halt' then
set i = GetRandomInt(1,2)
elseif id=='hlum' then
set i = GetRandomInt(4,6)
elseif id=='hbla' then
set i = GetRandomInt(11,14)
elseif id=='harm' then
set i = GetRandomInt(24,30)
elseif id=='hars' then
set i = GetRandomInt(55,65)
elseif id=='hgra' then
set i = GetRandomInt(90,120)
elseif id=='hwtw' then
set i = GetRandomInt(180,200)
elseif id=='htow' then
set i = GetRandomInt(10,15)
endif
something like below : JASS:function GameInti takes nothing returns nothing // basically runs during game intialization call StoreInteger(cache,"LowerValue",I2S('halt'),1) call StoreInteger(cache,"UpperValue",I2S('halt'),2) call StoreInteger(cache,"LowerValue",I2S('hlum'),4) call StoreInteger(cache,"UpperValue",I2S('hlum'),6) call StoreInteger(cache,"LowerValue",I2S('hbla'),11) call StoreInteger(cache,"UpperValue",I2S('hbla'),14) ... //and so on endfunction function GetInt takes integer i returns integer if HaveStoredInteger("LowerValue",I2S(i))!=0 then return GetRandomInt(GetStoredInteger(cache,"LowerValue",I2S(i)),GetStoredInteger(cache,"UpperValue",I2S(i))) endif return 0 endfunction |
| 03-02-2007, 05:15 PM | #2 |
First one. |
| 03-02-2007, 05:51 PM | #3 |
Depends how many unit types there can be. Game cache at least provides constant time for what that's worth, whereas the speed of the first solution heavily depends on how far down in the list the id is. |
| 03-02-2007, 07:44 PM | #4 |
could also build a binary tree of if/then/else |
| 03-03-2007, 01:34 AM | #5 |
hmph so where is the crossing line ? i mean how long the list go untill the game cache is faster instead ? |
| 03-03-2007, 08:34 AM | #6 |
If you use a binary tree, then probably around 2^10, I'd say, which is over 1000. That assumes five integer comparisons are equal to one gamecache call (which is about more likely to be low; non-array variables are lightning fast, as are comparisons). |
| 03-03-2007, 09:28 AM | #7 |
uhhhhh... sry... but what's a binary tree ? @@ can i have some link to study more ? :) |
