Dynamic array functions

A set of implicitly defined functions is available for each dynamic array. Many of these functions operate on either a one-dimensional array or on the first dimension of a multidimensional array only. Consider the following example:
  myIntArray INT[][] = [ [ 1,2], [3,4,5], [6,7,8,9] ]  ;
You can work around the one-dimensional array restriction. When you call any of the following functions, you qualify the function name with the name of the dynamic array. The name of the array can include pairs of brackets, each containing an index. For example:
  // remove element [3][2] (with the value 7)
  myIntArray[3].removeElement(2);

  // remove element [2] (entire row with the value [3,4,5])
  myIntArray.removeElement(2);

In the following sections, substitute the name of your array for arrayName.

appendAll()

  arrayName.appendAll(appendArray Array in)
This function does the following things:
  • Adds to the array that is referenced by arrayName, copying the elements of the array that is referenced by appendArray.
  • Increments the array size by the number of added elements. EGL throws a RuntimeException if the new size exceeds the array's maximum size.
  • Assigns an appropriate index value to each of the appended elements.

The elements of appendArray must be the same type as the elements of arrayName.

appendElement()

  arrayName.appendElement(content ArrayElement in)

This function places an element at the end of the specified array and increments the size of the array by one. The content you append can be any expression with a compatible type.

The rules for assigning a literal are specified in "Assignments."

getMaxSize()

  arrayName.getMaxSize ( ) returns (INT)

This function returns an integer that indicates the current maximum number of elements allowed in the array, as set by the maxSize property or by calling setMaxSize(). For multidimensional arrays, this value applies to the first dimension only.

getSize()

  arrayName.getSize ( ) returns (INT)

This function returns an integer that indicates the number of elements currently in the array. For multidimensional arrays, this value applies to the first dimension only. It is recommend that you use this function instead of sysLib.size() when you work with dynamic arrays.

insertElement()

  arrayName.insertElement (content ArrayElement in, index INT in)
This function does the following things:
  • Places an element in front of the element that is now at the specified location in the array.
  • Increments the array size by one. EGL throws a RuntimeException if the new size exceeds the maximum size of the array.
  • Increments the index of each element after the inserted element

content is the new content (of the appropriate type for the array), and index indicates the location of the new element.

If index is one greater than the number of elements in the array, the function creates a new element at the end of the array and increments the array size by one, which is the equivalent of calling the appendElement() function. If index is less than 1 or greater than the array size + 1, EGL throws an IndexOutOfBoundsException.

removeAll()

  arrayName.removeAll( )

This function removes the elements of the array from memory. The array can be used, but its size is zero.

removeElement()

  arrayName.removeElement(index INT in)

This function removes the element at the specified location, decrements the array size by one, and decrements the index of each element that resides after the removed element.

index indicates the location of the element to be removed. If index is less than 1 or greater than the size of the array, EGL throws an IndexOutOfBoundsException.

resize()

  arrayName.resize(size INT in)

This function adds or shrinks the current size of the array to the size specified in size. If the value of size is greater than the maximum size allowed for the array, EGL throws a RuntimeException.

reSizeAll()

  arrayName.reSizeAll(sizes INT[] in)

This function expands or shrinks every dimension of a multidimensional array. The parameter sizes is an array of integers, with each successive element specifying the size of a successive dimension. If the number of dimensions resized is greater than the number of dimensions in arrayName, or if the value of an element in sizes is greater than the maximum size allowed in the equivalent dimension of arrayName, EGL throws a RuntimeException.

If you shrink the size of the array, higher numbered elements are removed and their values lost.

setElementsEmpty()

  arrayName.setElementsEmpty ()

The function moves through the array, changing each element in the array to its initial state. For more information on initial values, see Data initialization.

setMaxSize()

  arrayName.setMaxSize (size INT in)

The function sets the maximum number of elements allowed in the array. If you set the maximum size to a value less than the current size of the array, EGL throws a RuntimeException.

setMaxSizes()

  arrayName.setMaxSizes(sizes INT[] in)

This function sets every dimension of a multidimensional array. The parameter sizes is an array of integers, with each successive element specifying the maximum size of a successive dimension. If the number of dimensions specified is greater than the number of dimensions in arrayName, or if a value of an element in sizes is less than the current number of elements in the equivalent dimension of arrayName, EGL throws a RuntimeException.


Feedback