Shift units in an array easily GUI

Status
Not open for further replies.
So I was thinking about some ideas for heroes I had and began wondering about if there is a way to easily shift all units inside an array by 1, say I make an array containing 6 units. I remove the first unit with index 0, then move the rest of the 5 from 1-5 to 0-4.
It's easily doable by assigning the units to a temporary array and then back with 1 less index, but is there an easier way?
 
But I thought arrays are fast. D:

At least compared to hashtables.

twice as fast actually, since a hashtable is a 2d array and a array is well, just an array. (and the fact that you tend to call functions to get the keys)

OT:
Sadly there is no way to get the array size directly. So you need to store that into a variable.

Loop from 0/1 to X and set your array to:
something[integer A/B - 1] = something[integer A/B]
@death Before you comment on it, I KNOW that integer a/b is slower.
 
twice as fast actually, since a hashtable is a 2d array and a array is well, just an array. (and the fact that you tend to call functions to get the keys)

A hashtable read / write is actually about 4-8 times slower than an array read / write. That means when looping through about 2-6 array indexes that the hashtable is a faster more efficient method. (Don't forget the ITE checks when looping through an array.)
 
Status
Not open for further replies.
Back
Top