Page 1 of 1
array.append() returning index
Posted: Sat Oct 18, 2008 12:55 am
by phao
Simple and useful suggestion.
append() method from array object could return the index of the element added.
Re: array.append() returning index
Posted: Sat Oct 18, 2008 10:01 am
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
Re: array.append() returning index
Posted: Sat Oct 18, 2008 11:39 pm
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.
Re: array.append() returning index
Posted: Sun Oct 19, 2008 1:45 am
by CWO
no it would not add to those values. It will only add at the end... at 8 in your example.
Re: array.append() returning index
Posted: Sun Oct 19, 2008 10:04 am
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