array.append() returning index

Archive of the older Feature Request Forum Posts

Moderator: POL Developer

Locked
phao
Grandmaster Poster
Posts: 129
Joined: Fri Aug 31, 2007 2:25 pm
Location: Brazil

array.append() returning index

Post by phao »

Simple and useful suggestion.

append() method from array object could return the index of the element added.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: array.append() returning index

Post by Austin »

What about your own user function?

arrays.inc

Code: Select all

function AppendToArrayEx(byref x_array, byref x_data)
     x_array.Append(x_data);
     return x_array.Size();
endfunction
phao
Grandmaster Poster
Posts: 129
Joined: Fri Aug 31, 2007 2:25 pm
Location: Brazil

Re: array.append() returning index

Post by phao »

I know the name is "append", but I though it could add at index different from 1 + the last one.

For example, having this array:

1 = used,
2 = used,
3 = empty,
4 = used,
5 = used,
6 = empty,
7 = used,

I though append(some value) would add at index 3, not at index 8.
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: array.append() returning index

Post by CWO »

no it would not add to those values. It will only add at the end... at 8 in your example.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: array.append() returning index

Post by Austin »

This would be horribly slow on a large array

Code: Select all

function InsertInAvailableArraySlot(byref x_array, byref x_data)
   foreach indice in ( x_array )
      if ( indice == error || !indice )
         x_array[_indice_iter] = x_data;
         return _indice_iter;
      endif
   endforeach
   x_array.Append(x_data);
   return x_array.Size();
endfunction
Locked