Aztec® Programming Language
Version 1.1 Alpha 2

Copyright © 2010-2017, Aztec Development Group, All Rights Reserved

Download Aztec

Search        Contact Us

She won't let you fly...

But she might let you sing.

- Roger Waters

 

When an array is referenced without using array braces, a set of methods is available to perform operations on the array. These methods are available to every array, regardless of the data type, number of array dimensions, or whether the array was dynamically allocated or its size was defined at compile time.

Array Methods

Size() Returns the total size of the array
Size() Returns the size of one dimension in the array
Dimensions() Returns the number of dimensions in the array
ArrayId() Returns the unique Array Id for this array
ArrayClass() Returns the Class metadata object corresponding to the data type of the array
Clear() Clears the contents of each element in the array
AutoResize() Returns the current value of the "auto resize" flag, which controls auto resizing of this array
SetAutoResize() Sets the value of the "auto resize" flag, which controls auto resizing of arrays
Resize() Manually resizes the first dimension of the array
Resize() Manually resizes any dimension of the array
Sort() Performs a Sort operation on the array with several comparison options

See Also

 


Size()

public method<int> Size()

Parameters

None

Return Value

Total size (number of elements) of the array

Description

Returns the total size for the array, accounting for all of the dimensions in the array. For a three dimensional array with 10, 20 and 30 elements, respectively, the method will return a size of 6000.

 

Array


Size()

public method<int> Size(int Dimension)

Parameters

Dimension

One based array dimension

Return Value

Total size (number of elements) in the specified dimension of the array.

Description

Returns the number of elements in a single dimension of an array. For a three dimensional array with 10, 20 and 30 elements, respectively, the method will return a size of 20 for a Dimension of 2..

 

Array


Dimensions()

public method<int> Dimensions()

Parameters

None

Return Value

Number of dimensions in the array

Description

Returns the number of dimensions in the array.

 

Array


ArrayId()

public method<int> ArrayId()

Parameters

None

Return Value

Unique array ID

Description

Returns the unique Array Id. The Array Id is created and assigned by the Aztec Virtual Machine when the array is created. Array Ids are distinct and separate from Aztec Object Ids, but they work in a similar fashion. When the VM starts up, the starting point for Array Ids is randomly selected within a specific range (different from the range used by object Ids), and then the Array Ids are incremented from there with each successive dynamic allocation.

 

When comparing two Aztec array objects, it will always be true that the array with the smaller Array Id is "older".

 

Array


ArrayClass()

public method<Class> ArrayClass()

Parameters

None

Return Value

Class object corresponding to array data type

Description

Returns a reference to a Class object that corresponds to the data type associated with the array.

 

Array


Clear()

public method Clear()

Parameters

None

Return Value

None

Description

Clears all of the elements from the array, but does not resize the array. It effectively sets each element in the array with the default value for that data type. For arrays of primitive values, each element is set with the default value for that primitive type (0 for int, 0.0 for float, "" for string, etc.). For arrays ofprimitive references or any type of non-primitive class, each element is set with null.

 

Array


AutoResize()

public method<bool> AutoResize()

Parameters

None

Return Value

Value of the "auto resize" flag for the array

Description

This method returns the current value of the auto resize flag for this array. The value is false by default for all arrays, but each array can be set to true if needed. If an array's auto resize flag is false, accessing an element that is outside the current size of the array will cause an array exception. But if the auto resize flag is turned on, the array will automatically be resized and the request satisfied. If the array is resized, all newly created elements will be properly initialized based on the array data type.

 

Array


SetAutoResize()

public method SetAutoResize(bool AutoResize = true)

Parameters

AutoResize

New value for auto resize flag for this array (true by default)

Return Value

None

Description

This method is used to set the value of the auto resize flag for this array. The value is false by default for all arrays, but each array can be set to true if needed. If an array's auto resize flag is false, accessing an element that is outside the current size of the array will cause an array exception. But if the auto resize flag is turned on, the array will automatically be resized and the request satisfied. If the array is resized, all newly created elements will be properly initialized based on the array data type.

 

Array


Resize()

public method Resize(int NewSize)

Parameters

NewSize

New size for the first dimension of the array

Return Value

None

Description

This method resizes the first dimension of array. It works for one dimensional and multi-dimensional arrays. If the array is resized to be bigger, all newly created elements will be properly initialized based on the array data type. If it is resized to be smaller, all elements in the array which are eliminated are properly cleaned up based on the array data type.

 

Array


Resize()

public method Resize(int Dimension, int NewSize)

Parameters

Dimension

One based dimension to be resized

NewSize

New size for the first dimension of the array

Return Value

None

Description

This method resizes the specified dimension of array. It works for one dimensional and multi-dimensional arrays. If the array dimension is resized to be bigger, all newly created elements will be properly initialized based on the array data type. If it is resized to be smaller, all elements in the array which are eliminated are properly cleaned up based on the array data type.

 

Array


Sort()

public method Sort(BaseSortHandler CompareHandler, bool Ascending = true, Base ExtraObject = null, int StartIndex = 1, int EndIndex = 0)

Parameters

CompareHandler

Handler to be used for comparison

Ascending

Sorts in ascending fashion if true and descending if false (true by default)

ExtraObject

Extra object to be passed to the comparison method (null by default)

StartIndex

Array index for start of the sort operation (1 by default)

EndIndex

Array index for end of the sort operation (0 by default)

Return Value

None

Description

This method performs a sort operation on the array. The entire array can be sorted, or just a portion of the array can be sorted. The StartIndex and EndIndex are used to specify the portion of the array to be sorted. If EndIndex is 0, the end of the array is used, so the default (StartIndex of 1 and EndIndex of 0) causes the entire array to be sorted. If StartIndex is greater than 1, and EndIndex is less than the number of elements, just that portion of the array will be sorted.

 

The sort operation works by performing a comparison between two elements at a time, and repeating the process until the entire array (or subset) has been sorted. The comparison can be performed in two different ways.

 

If the ComparHandler is null, the system performs an automatic comparison based on the data type of the array. If the array contains primitive data (value or reference), standard comparison rules will be used for the value. If the array contains non-primitive Class objects, the default comparison will be performed against the ObjectId of each element.

 

If the CompareHandler is not null, the system invokes that handler to perform the operatiion. Since the same handler type needs to be used for arrays of all types, the arguments to the handler will be generic in nature (Base). The BaseSortHandler data type is the method reference used to define the comparison method for the array Sort method, and it is defined as follows.

 

        public type<int method<Base,Base,bool,Base>> BaseSortHandler

 

Given this definition, the method handler must be defined with the following signature (name can be anything):

 

        method<int> CompareMethod(Base FirstCompareItemt, Base SecondCompareItem, bool Ascend, Base ExtraObject) { }

 

The code in the method will need to convert these two "Base" pointers to the actual type of data that is being analyzed. The third argument is the same Ascend flag and the fourth argument is the same ExtraObject reference that were passed into the Sort method, so they are available to the comparison methods. The ExtraObject argument is application specific, but the Ascend flag should be honored and the comparison result should take the Ascend flag into consideration. Once the application specific comparison logic has been performed, If the two items are considered equal, the comparison method should return 0, If FirstCompareItem is greater than SecondCompareItem, it should return 1 and if the first is less than the second it should return (-1).

 

This array Sort method is a convenient option for sorting, but it also requires the user of the method to handle the comparison data as generic (Base) data. There is also a separate QuickSort<T> template class that can be used to perform sort operations on an array, and the comparison methods are specific to the data type in question. It provides a much more eloquent solution to the sorting process.

 

Array

 

Copyright © 2010-2017

Aztec Development Group

All Rights Reserved

Download Aztec