Overview
Examples
Code
Usage
Table
| Commonly in the bits of the integers space exists that is not being used, with this we can get the most out of each integer creating a pocket array that allows us to store new data. It can also be seen as preventing leaks at the bit level because compressing variables and therefore not using them can be interpreted as destroying or deleting them from memory. Otherwise, without this algorithm, you would have to use more variables in memory. Compression, leaks, bitmasking regardless of we see it will allow you reduce to 32KB per MB of boolean variables and from 512KB to 51,2KB per MB of integer variables. |
Let's say we have a map with 12 players and stores 6 posible states in a global integer variables for each of the players, with values ranging from 0 to 5. Looking at the table, we can replace by only 1 integer variable.
Without gics, we would use (32 bits)(12) = 384 bits in global variables.
With gics, we would use (32 bits)(1) = 32 bits in global variables.
we would have a 1100% resource saving.
Another potential case is if we had global booleans (Blizzard uses 32 bits) and wanted to use gics. Looking at the table, we could compress 32 global booleans into 1 global integer.
Without gics, we would use (32 bits)(32) = 1024 bits in global variables.
With gics, we would use (32 bits)(1) = 32 bits in global variables.
we would have a 3100% resource saving.
JASS
GUI
Lua
JASS:
function gics takes integer index, integer newvalue returns integer
local integer m = //maximun integer value//
local integer a = 1
local integer b = m + 1
if index > 0 then
loop
exitwhen a > index
set b = b * (m + 1)
set a = a + 1
endloop
endif
set a = (YourGlobal + 2147483648) / b
set a = YourGlobal + 2147483648 - b * a
set a = a / (b / (m + 1))
if newvalue < 0 then
return a
else
set YourGlobal = YourGlobal + (newvalue - a) * (b / (m + 1))
return 0
endif
endfunction
JASS:
globals
integer YourGlobal = -2147483648
endglobals
-
gics
-

Events
-


Player - Player 1 (Red) Presses the Escape key
-
-

Conditions
-

Actions
-


-------- this for set -------- replace every 5.00 for your maximun integer value, every 2.00 for you index, and located in the Set Variable action the 3 for the newvalue of the index --------
-


For each (Integer A) from (((YourGlobal + (32768 x 65536)) mod (Integer((Power((5.00 + 1.00), (2.00 + 1.00)))))) / (Integer((Power((5.00 + 1.00), 2.00))))) to (Integer A), do (Actions)
-



Loop - Actions
-




Set YourGlobal = (YourGlobal + ((3 - (Integer A)) x (Integer((Power((5.00 + 1.00), 2.00))))))
-
-
-


-------- this for get -------- replace every 5.00 for your maximun integer value, every 2.00 for you index, (Integer A) is the output --------
-


For each (Integer A) from (((YourGlobal + (32768 x 65536)) mod (Integer((Power((5.00 + 1.00), (2.00 + 1.00)))))) / (Integer((Power((5.00 + 1.00), 2.00))))) to (Integer A), do (Actions)
-



Loop - Actions
-




Game - Display to (All players) the text: (String((Integer A)))
-
-
-
-
-
Map initialization
-

Events
-


Map initialization
-
-

Conditions
-

Actions
-


Set YourGlobal = (-32768 x 65536)
-
-
Lua:
function gics(index, newvalue)
local m = --maximun integer value--
local a = 1
local b = m + 1
while a <= index do
b = b * (m + 1)
a = a + 1
end
a = (YourGlobal + 2147483648) // b
a = YourGlobal + 2147483648 - b * a
a = a // (b // (m + 1))
if newvalue < 0 then
return a
else
YourGlobal = YourGlobal + (newvalue - a) * (b // (m + 1))
return 0
end
end
Lua:
YourGlobal = -2147483648
The values of the integers that it can store range from 0 up to the //maximun integer value//, which will be configured as needed. From this maximum value, a range of indices will be obtained, also starting at 0 (like an array). The number of these indices will be inversely proportional to the maximum integer value, according to the Table.
gics("index", "newvalue")
to use for set
"index"=0,1,... // as far as possible according to the table
"newvalue"=0,1,... // as far as possible according you maximum integer value
ex: gics(0, 4)
for get
"index"=0,1,... // as far as possible according to the table
"newvalue"<0 // It doesn't matter, just put a negative number.
ex: gics(0, -1)
output:4 // if you did it as in the previous example
You can expand its use for different maximum integer values by adding argument and conditional to differentiate them, then the function take another global integer variable and another maximum integer value. Alternatively, you can copy the function with a different name and modify the two parameters mentioned.
gics("index", "newvalue")
to use for set
"index"=0,1,... // as far as possible according to the table
"newvalue"=0,1,... // as far as possible according you maximum integer value
ex: gics(0, 4)
for get
"index"=0,1,... // as far as possible according to the table
"newvalue"<0 // It doesn't matter, just put a negative number.
ex: gics(0, -1)
output:4 // if you did it as in the previous example
You can expand its use for different maximum integer values by adding argument and conditional to differentiate them, then the function take another global integer variable and another maximum integer value. Alternatively, you can copy the function with a different name and modify the two parameters mentioned.
maximun integer value=#values-1max index=array lenght-1| #values (0 to maximun integer value) | array lenght (0 to max index) |
| 2 | 32 |
| 3 | 20 |
| 4 | 16 |
| 5 | 13 |
| 6 | 12 |
| 7 | 11 |
| 8-9 | 10 |
| 10-11 | 9 |
| 12-16 | 8 |
| 17-24 | 7 |
| 25-40 | 6 |
| 41-84 | 5 |
| 85-256 | 4 |
| 257-1625 | 3 |
| 1626-65536 | 2 |
Last edited:



