DIFF

class array<Class T>Source

Part of Enforce script essentials

Methods 28

proto native int Count()

O(1) complexity.

Returns: Number of elements of the array

proto native void Clear()

Destroyes all elements of the array and sets the Count to 0. The underlying memory of the array is not freed.

proto int Find(T value)

Tries to find the first occurance of given value in the array.

Returns: Index of the first occurance of `value` if found, -1 otherwise

proto T Get(int n)

Returns: Element at the index `n`

proto int Insert(T value)

Inserts element at the end of array.

value
Element to be inserted

Returns: Position at which element is inserted

void InsertAll(notnull array<T> from)

Inserts all elements from array

from
array<T> array from which all elements will be added
TStringArray arr1 = new TStringArray;
arr1.Insert( "Dave" );
arr1.Insert( "Mark" );
arr1.Insert( "John" );

TStringArray arr2 = new TStringArray;
arr2.Insert( "Sarah" );
arr2.Insert( "Cate" );

arr1.InsertAll(arr2);

for ( int i = 0; i < arr1.Count(); i++ )
{
	Print( arr1.Get(i) );
}

delete arr2;
delete arr1;

>> "Dave"
>> "Mark"
>> "John"
>> "Sarah"
>> "Cate"
References Count(), Get(), and Insert()
proto native void Remove(int index)

Removes element from array. The empty position is replaced by last element, so removal is quite fast but do not retain order.

index
Index of element to be removed
proto native void RemoveOrdered(int index)

Removes element from array, but retain all elements ordered. It's slower than Remove

index
Index of element to be removed
proto native void Resize(int newSize)

Resizes the array to given size. If the `newSize` is lower than current Count overflowing objects are destroyed. If the `newSize` is higher than current Count missing elements are initialized to zero (null).

proto native void Reserve(int newSize)

Resizes the array to given size internally. Is used for optimization purposes when the approx. size is known beforehand

proto native void Swap(notnull array<T> other)

Swaps the contents of this and `other` arrays. Does not involve copying of the elements.

proto int Init(T init[])
void RemoveItemUnOrdered(T value)
References Find(), and Remove()
void Debug()

Print all elements in array

Returns: void

my_array.Debug();

>> "One"
>> "Two"
>> "Three"
References Count(), string.Format(), Get()
Show 1 more, Print()
int GetRandomIndex()

Returns a random index of array. If Count is 0, return index is -1 .

Returns: int Random index of array

Print( my_array.GetRandomIndex() );

>> 2
References Count(), and Math.RandomInt()
void SwapItems(int item1_index, int item2_index)
References Get(), and Set()
int MoveIndex(int curr_index, int move_number)

Returns a index in array moved by specific number

Returns: int Moved index in this array

Print( "Count: "+ my_array.Count() );
Print( "Moved 1:"+ my_array.MoveIndex(2, 1) );
Print( "Moved 3:"+ my_array.MoveIndex(2, 2) );

>> "Count: 4"
>> "Moved index 2 by 1: 3";
>> "Moved index 2 by 2: 0";
References Count()
int DifferentAtPosition(array<T> pOtherArray)

Returns an index where 2 arrays start to differ from each other

Returns: int Index from where arrays differ

array<int> arr1 = {0,1,2,3};
array<int> arr2 = {0,1,3,2};
int differsAt = arr1.DifferentAtPosition(arr2);
Print(differsAt);

>> 2
References Count(), Count(), ErrorEx()
Show 2 more, Get(), and Get()