Adding emtpy rows and columns to a two dimensional array with DIMPUSH

Previous topic - Next topic

Marmor

its time for transfer (arrayx[],arrayy[],start,len) to kill the basic overhead  :noggin:

S.O.P.M.

Now I've written a new shifting procedure that uses less code and hopyfully will work for any given array but if it will run with similar speed that's the next question. At first I copied element by element inside two loops. Now I copy the whole array to another array with ArrCop[] = Arr[] and then paste the copy to the original with the given x and y offset. Still clearing the remaining elements with a new loop would be stupid. The following code is untested, please take a look on it and tell me what do you think it's the best way to do the task by using basic only. To remember, I need to shift the contents of any array with a single procedure to any extension - using basic code only, as less as possible and fast.

Code (glbasic) Select
FUNCTION ShiftArray: Arr%[], XExt%, YExt%

LOCAL ArrCop%[]
LOCAL ACX%, ACY%
LOCAL AX%, AY%
LOCAL W%, H%

IF XExt < 0
    ACX = ABS(XExt)
ELSE
    AX = XExt
ENDIF
IF YExt < 0
    ACY = ABS(YExt)
ELSE
    AY = YExt
ENDIF
W = BOUNDS(Arr[], 0)
H = BOUNDS(Arr[], 1)
ArrCop[] = Arr[]
FOR i = AX TO H - AY - 1
    FOR j = AY TO W - AX - 1
        Arr[AX + j][AY + i] = ArrCop[ACX + j][ACY + i]
    NEXT
NEXT

ENDFUNCTION


Zeroization is still not in there. XExt and YExt are the given movements, positive values shift right, negative ones left. ACX and ACY are the start coordinates where the copy will read, AX and AY the coordinates to start writing on the origin array. Would like to replace the first two IF-ENDIF's by formulas to set the right values but can't figure out how. Finally want to build the zeroization inside the double loop not using another one for that.
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium

Hemlos

My lib uses arrays is a few ways, maybe you can use some of this code, or use the lib itself.
You can see in the image here, a function list for controlling arrays.
In your case here, you would be looking at the pop del and shift functions.

Feel free to use the whole library, its all compatible to each object type...some depend on each other.
By type i mean; strings, lists, files, time, and terminals.
You can get it from my download page.

http://silver.binhoster.com/downloads.html

PS. i will be updating that library again this year i hope. Im thinking about the 3d particle engine as part of the lib too.
Bing ChatGpt is pretty smart :O

S.O.P.M.

Seems to be some fantastic and useful work, many thanks. That's fine  :)
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium