- Joined
- Feb 22, 2006
- Messages
- 960
Thats what i got so far, i added textmacros for more variable types which will be suported in the future. it only supports integers actually
the problem is, that u only can have actually 1 pseudo array (will improve system for more)
here the code:
the problem is, that u only can have actually 1 pseudo array (will improve system for more)
here the code:
JASS:
//****************************************************************
//* Pseudo-Array System [v0.1]
//* By xD.Schurke
//* 06.01.2009
//****************************************************************
//! textmacro Arrays takes NAME, TYPE
library $NAME$arrays
globals
private constant integer max = 8190
private $NAME$Array $NAME$Object
endglobals
struct $NAME$Array
$TYPE$ array $NAME$ [max]
integer $NAME$counter = 0
//initializes the new pseudo-array
static method new takes nothing returns $NAME$Array
local $NAME$Array dat = $NAME$Array.allocate()
set $NAME$Object = dat
return dat
endmethod
//adds a value to the pseudo-array
static method add takes $TYPE$ var returns nothing
set $NAME$Object.$NAME$[$NAME$Object.$NAME$counter] = var
set $NAME$Object.$NAME$counter = $NAME$Object.$NAME$counter + 1
endmethod
//gets the value at the index u want
static method get takes integer index returns $TYPE$
return $NAME$Object.$NAME$[index]
endmethod
//sorts the values in the pseudo-array
static method sort takes integer count returns nothing
local integer i = 0
local integer j = 0
local integer k = 0
if count > max then
return
endif
loop
set j = 0
loop
if $NAME$Object.$NAME$[j] > $NAME$Object.$NAME$[j+1] then
set k = $NAME$Object.$NAME$[j]
set $NAME$Object.$NAME$[j] = $NAME$Object.$NAME$[j+1]
set $NAME$Object.$NAME$[j+1] = k
endif
set j = j + 1
exitwhen j >= count - i
endloop
set i = i + 1
exitwhen i >= count
endloop
endmethod
//searchs for a value in the pseudo-array and returns the position of the value
static method seach takes $TYPE$ var returns integer
local integer left = 0
local integer right = $NAME$Object.$NAME$counter - 1
local integer mid = 0
loop
set mid = R2I((I2R(left+right)/2)+0.5)
if $NAME$Object.$NAME$[mid] == var then
return mid
elseif $NAME$Object.$NAME$[mid] > var then
set right = mid - 1
elseif $NAME$Object.$NAME$[mid] < var then
set left = mid + 1
endif
exitwhen left >= right
endloop
return 0
endmethod
endstruct
endlibrary
//! endtextmacro
//! runtextmacro Arrays("Integer","integer")