Libraries.Containers.Array Documentation

The Array class is a data structure that stores items in contiguous memory. An item is typically stored and accessed through an index or location. This location always starts at 0, this means the first item in the array is at location 0, the second is at location 1, etc. The default maximum size is set to 10, but can be changed by using the SetSize(value) method or the array will automatically make itself large when the space is needed (note: it is possible to turn the resizing off with the SetAutoResize(false) method).

Example Code

use Libraries.Containers.Array
class Main
   action Main
      //make the array
      Array<integer> myArray
      //add a value
      myArray:Add(12)
      //get it back
      integer value = myArray:Get(0)
   end
e

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
Add(integer location, Type value)This action adds a value at a location in the indexed object.
Add(Type value)This action adds a value to the end of the array.
AddToEnd(Type value)This action adds an item to the end of the array.
AddToFront(Type value)This action adds an item to the front of the array at index 0.
ClearContents(integer start, integer stop)This action clears out any remnant objects.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Copy()This action returns a deep copy of the array in question.
CopyToArray()This action copies the list to an array data structure.
Empty(boolean value)This action empty's the list.
Empty()This action empty's the list, clearing out all of the items contained within it.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
Get(integer location)This action gets the item at a given location in an array.
GetAutoResize()This action returns true if the array is dynamic(resizable) or false if the array does not automatically resize.
GetFirstLocation(Type value)This action gets the first occurrence of the item and returns its location.
GetFromEnd()This action gets the item at the end of the array(the item will remain in the array).
GetFromFront()This action gets the item at the front of the array(the item will remain in the array).
GetHashCode()This action gets the hash code for an object.
GetIterator()This action gets an iterator for the object and returns that iterator.
GetLastLocation(Type value)This action gets the last occurrence of the item and returns its location.
GetMaxSize()This action gets the number of items that can be stored in the array(max size).
GetSize()This action gets the size of the array.
Has(Type value)This action determines if an addable object contains a certain item.
IsEmpty()This action returns a boolean value, true if the container is empty and false if it contains any items.
Remove(Type value)This action removes the first occurrence of an item that is found in the Addable object.
RemoveAll(Type value)This action removes all occurrences of an item from the Addable object.
RemoveAt(integer location)This action removes an item from an indexed object and returns that item.
RemoveFromEnd()This action removes the item at the end of the array.
RemoveFromFront()This action removes the item at the front of the list.
Set(integer location, Type value)This action sets the item at a given location in the indexed object to a new item.
SetAutoResize(boolean resizable)This action changes the flag that tells the structure if it is a dynamic array or not.
SetMaxSize(integer size)This action sets the number of items that can be stored in the array(max size).
SetSize(integer size)This action sets the size of the array and fills it with undefined items.
Sort(Libraries.Containers.Support.Comparison comparison)This action sorts the values of the array using a merge sort algorithm.
Sort()This action sorts the values of the array using a merge sort algorithm.
Sort(Libraries.Containers.Support.Comparison comparison, Libraries.Containers.Array<Type> temp)This action sorts the values of the array using a merge sort algorithm.

Actions Documentation

Add(integer location, Type value)

This action adds a value at a location in the indexed object.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:Add(0, 2

Parameters

Add(Type value)

This action adds a value to the end of the array.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:Add(2

Parameters

AddToEnd(Type value)

This action adds an item to the end of the array. If the max size has been reached an the array is not re-sizable an InvalidLocationError will be alerted.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:AddToEnd(1

Parameters

AddToFront(Type value)

This action adds an item to the front of the array at index 0. Then moves all other items down one index. If the max size is already reached and the array is not re-sizable an InvalidLocationError will be alerted.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:AddToFront(1

Parameters

ClearContents(integer start, integer stop)

This action clears out any remnant objects. This should only be used if Empty(false) was use

Parameters

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Example Code

Object o
        Object t
        integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smalle

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Copy()

This action returns a deep copy of the array in question. As such, all elements are copied from one array to the other. While the array is a deep copy, the elements inside of the array are not copied.

Example Code

//the array class is Copyable
        use Libraries.Containers.Array
        Array<integer> array
        Object o = array:Copy()
        Array<integer> copy = cast(Array<integer>,

Return

Libraries.Language.Object: Returns a deep copy of the array.

CopyToArray()

This action copies the list to an array data structure.

Return

Libraries.Containers.Array: This returns an array of the lis

Empty(boolean value)

This action empty's the list. While this does set the size to 0, this version of empty does not clear out the contents. The reason for this is that some algorithms need to manage the memory manually for efficiency.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(10)
        myArray:Set(0, 22) 
        myArray:Set(1, 33)
        myArray:Set(2, 45)
        myArray:Set(3, 22)
        myArray:Empty

Parameters

Empty()

This action empty's the list, clearing out all of the items contained within it.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(10)
        myArray:Set(0, 22) 
        myArray:Set(1, 33)
        myArray:Set(2, 45)
        myArray:Set(3, 22)
        myArray:Empty

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Get(integer location)

This action gets the item at a given location in an array.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(10)
        myArray:Set(0, 22)
        integer result = myArray:Get(

Parameters

Return

Libraries.Language.Object: The item at the given location.

GetAutoResize()

This action returns true if the array is dynamic(resizable) or false if the array does not automatically resize.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        boolean result = myArray:GetAutoResize

Return

boolean: True if the array is resizable and false if it is not.

GetFirstLocation(Type value)

This action gets the first occurrence of the item and returns its location. If the item was not found -1 is returned.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(10)
        myArray:Set(0, 22) 
        myArray:Set(1, 33)
        myArray:Set(2, 45)
        myArray:Set(3, 22)
        integer location = myArray:GetFirstLocation(2

Parameters

Return

integer: The location of the first occurrence of the item.

GetFromEnd()

This action gets the item at the end of the array(the item will remain in the array).

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:Add(4)
        myArray:Add(13)
        myArray:Add(12)
        integer value = myArray:GetFromEnd

Return

Libraries.Language.Object: The item at the end of the array.

GetFromFront()

This action gets the item at the front of the array(the item will remain in the array).

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:Add(4)
        myArray:Add(13)
        myArray:Add(12)
        integer value = myArray:GetFromFront

Return

Libraries.Language.Object: The item at the front of the array.

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode

Return

integer: The integer hash code of the object.

GetIterator()

This action gets an iterator for the object and returns that iterator.

Example Code

use Libraries.Containers.Array
        use Libraries.Containers.Iterator

        Array<integer> myArray
        myArray:SetSize(4)
        myArray:Set(0, 22) 
        myArray:Set(1, 33)
        myArray:Set(2, 45)
        myArray:Set(3, 22)
        Iterator<integer> it = myArray:GetIterator

Return

Libraries.Containers.Iterator: Returns the iterator for an object.

GetLastLocation(Type value)

This action gets the last occurrence of the item and returns its location. If the item was not found -1 is returned.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(10)
        myArray:Set(0, 22) 
        myArray:Set(1, 33)
        myArray:Set(2, 45)
        myArray:Set(3, 22)
        integer location = myArray:GetLastLocation(2

Parameters

Return

integer: The location of the last occurrence of the item.

GetMaxSize()

This action gets the number of items that can be stored in the array(max size).

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        integer maxSize = myArray:GetMaxSize

Return

integer:

GetSize()

This action gets the size of the array.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        integer size = myArray:GetSize

Return

integer:

Has(Type value)

This action determines if an addable object contains a certain item.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(10)
        myArray:Set(0, 22) 
        myArray:Set(1, 33)
        myArray:Set(2, 45)
        myArray:Set(3, 22)
        boolean result = myArray:Has(3

Parameters

Return

boolean: Returns true if the item was in the Addable object and false if it was not.

IsEmpty()

This action returns a boolean value, true if the container is empty and false if it contains any items.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(10)
        myArray:Set(0, 22) 
        myArray:Set(1, 33)
        myArray:Set(2, 45)
        myArray:Set(3, 22)
        boolean result = myArray:IsEmpty

Return

boolean: Returns true when the container is empty and false when it is not.

Remove(Type value)

This action removes the first occurrence of an item that is found in the Addable object.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(10)
        myArray:Set(0, 22) 
        myArray:Set(1, 33)
        myArray:Set(2, 45)
        myArray:Set(3, 22)
        boolean result = myArray:Remove(2

Parameters

Return

boolean: Returns true if the item was removed and false if it was not removed.

RemoveAll(Type value)

This action removes all occurrences of an item from the Addable object.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(10)
        myArray:Set(0, 22) 
        myArray:Set(1, 33)
        myArray:Set(2, 45)
        myArray:Set(3, 22)
        boolean result = myArray:RemoveAll(2

Parameters

Return

boolean: Returns true if the item was removed and false if it was not removed.

RemoveAt(integer location)

This action removes an item from an indexed object and returns that item.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(10)
        myArray:Set(0, 22) 
        myArray:Set(1, 33)
        myArray:Set(2, 45)
        myArray:Set(3, 22)
        integer item = myArray:RemoveAt(

Parameters

Return

Libraries.Language.Object: The item that was removed from the indexed object.

RemoveFromEnd()

This action removes the item at the end of the array.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:Add(33)
        myArray:Add(13)
        myArray:Add(43)
        integer removed = myArray:RemoveFromEnd

Return

Libraries.Language.Object: The item at the end of the array.

RemoveFromFront()

This action removes the item at the front of the list.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:Add(33)
        myArray:Add(13)
        myArray:Add(43)
        integer removed = myArray:RemoveFromFront

Return

Libraries.Language.Object: The item at the front of the list.

Set(integer location, Type value)

This action sets the item at a given location in the indexed object to a new item.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(10)
        myArray:Set(0, 2

Parameters

SetAutoResize(boolean resizable)

This action changes the flag that tells the structure if it is a dynamic array or not. If it is dynamic(an array list) then resizable is true and if it is a standard array(not dynamic) then resizable is false.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetAutoResize(false)
        myArray:SetSize(1

Parameters

SetMaxSize(integer size)

This action sets the number of items that can be stored in the array(max size). The max size can only be increased, any value that is lower will leave the array with the same max size it had.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetMaxSize(2

Parameters

SetSize(integer size)

This action sets the size of the array and fills it with undefined items. Changing the size of the array means any items already in the array will be copied over.

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:SetSize(1

Parameters

Sort(Libraries.Containers.Support.Comparison comparison)

This action sorts the values of the array using a merge sort algorithm. It is guaranteed to execute in O(n log n). The example uses a support class called IntegerComparison, which duplicates the default sorting for integers.

Example Code

use Libraries.Containers.Support.Comparison
        class IntegerComparison is Comparison
            action Compare(Object left, Object right) returns integer
                Integer l = cast(Integer, left)
                Integer r = cast(Integer, right)
                if l:GetValue() < r:GetValue()
                    return parent:Comparison:SMALLER
                elseif l:GetValue() > r:GetValue()
                    return parent:Comparison:LARGER
                else
                    return parent:Comparison:EQUAL
                end
            end
        end

        use Libraries.Containers.Array
        Array<integer> myArray
        IntegerComparison compare
        myArray:Add(33)
        myArray:Add(13)
        myArray:Add(43)
        myArray:Sort(compar

Parameters

Sort()

This action sorts the values of the array using a merge sort algorithm. It is guaranteed to execute in O(n log n).

Example Code

use Libraries.Containers.Array
        Array<integer> myArray
        myArray:Add(33)
        myArray:Add(13)
        myArray:Add(43)
        myArray:Sort

Sort(Libraries.Containers.Support.Comparison comparison, Libraries.Containers.Array<Type> temp)

This action sorts the values of the array using a merge sort algorithm. It is guaranteed to execute in O(n log n). The example uses a support class called IntegerComparison, which duplicates the default sorting for integers. This version requires passing a comparison object and an equally sized array to use as temporary storage.

Example Code

use Libraries.Containers.Support.Comparison
        class IntegerComparison is Comparison
            action Compare(Object left, Object right) returns integer
                Integer l = cast(Integer, left)
                Integer r = cast(Integer, right)
                if l:GetValue() < r:GetValue()
                    return parent:Comparison:SMALLER
                elseif l:GetValue() > r:GetValue()
                    return parent:Comparison:LARGER
                else
                    return parent:Comparison:EQUAL
                end
            end
        end

        use Libraries.Containers.Array
        Array<integer> myArray
        Array<integer> temp
        IntegerComparison compare
        myArray:Add(33)
        myArray:Add(13)
        myArray:Add(43)
        myArray:Sort(compare, tem

Parameters