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
end

Inherits from: Libraries.Language.Object

Actions Documentation

Add(Type value)

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

Parameters

Example

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

Add(integer location, Type value)

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

Parameters

  • integer location: The index or location the value will be stored at.
  • Libraries.Language.Object: The item to be added to the indexed object.

Example

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

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.

Parameters

Example

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

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.

Parameters

Example

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

ClearContents(integer start, integer stop)

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

Parameters

  • integer start
  • integer stop

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.

Parameters

Return

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

Example

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

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.

Return

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

Example

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

CopyToArray()

This action copies the list to an array data structure.

Return

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

Empty()

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

Example

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()

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.

Parameters

  • boolean value

Example

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.

Parameters

Return

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

Example

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

Get(integer location)

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

Parameters

  • integer location: The index or location the value is located at.

Return

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

Example

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

GetAutoResize()

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

Return

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

Example

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

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.

Parameters

Return

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

Example

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(22)

GetFromEnd()

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

Return

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

Example

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

GetFromFront()

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

Return

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

Example

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

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetIterator()

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

Return

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

Example

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()

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.

Parameters

Return

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

Example

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(22)

GetMaxSize()

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

Return

integer:

Example

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

GetSize()

This action gets the size of the array.

Return

integer:

Example

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

Has(Type value)

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

Parameters

Return

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

Example

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(33)

IsEmpty()

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

Return

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

Example

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()

Remove(Type value)

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

Parameters

Return

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

Example

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(22)

RemoveAll(Type value)

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

Parameters

Return

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

Example

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(22)

RemoveAt(integer location)

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

Parameters

  • integer location: The index or location of the item to remove.

Return

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

Example


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(2)

RemoveFromEnd()

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

Return

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

Example

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

RemoveFromFront()

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

Return

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

Example

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

Set(integer location, Type value)

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

Parameters

  • integer location: The index or location the value will be stored at.
  • Libraries.Language.Object: The item to be added to the indexed object.

Example

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

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.

Parameters

  • boolean resizable: The value to set the resizable flag to.

Example

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

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.

Parameters

  • integer size: The max size to set for the array.

Example

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

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.

Parameters

  • integer size: The size of the array.

Example

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

Shuffle()

This action shuffles the values in the array randomly.

Example

use Libraries.Containers.Array
constant integer max = 20
Array<integer> values
i = 0
repeat while i < max
    values:Add(i)
    i = i + 1
end

values:Shuffle()

i = 0
repeat while i < max
    output values:Get(i)
    i = i + 1
end

Shuffle(integer minimum, integer maximum)

This action shuffles the values in the array randomly. In this version, a minimum and maximum part of the array is provided. If those values are outside the bounds of the array, they are clamped to correct values.

Parameters

  • integer minimum: The smallest index to shuffle
  • integer maximum: The largest index to shuffle

Example

use Libraries.Containers.Array
constant integer max = 20
Array<integer> values
i = 0
repeat while i < max
    values:Add(i)
    i = i + 1
end

values:Shuffle(3, 7) //Only shuffle part of the array

i = 0
repeat while i < max
    output values:Get(i)
    i = i + 1
end

Shuffle(integer minimum, integer maximum, number seed)

This action shuffles the values in the array randomly. In this version, a minimum and maximum part of the array is provided. If those values are outside the bounds of the array, they are clamped to correct values. This version also uses a random number seed.

Parameters

  • integer minimum: The smallest index to shuffle
  • integer maximum: The largest index to shuffle
  • number seed: The seed for the random number generator

Example

use Libraries.Containers.Array
constant integer max = 20
Array<integer> values
i = 0
repeat while i < max
    values:Add(i)
    i = i + 1
end

values:Shuffle(3, 7, 0) //Only shuffle part of the array and pass a random seed

i = 0
repeat while i < max
    output values:Get(i)
    i = i + 1
end

Shuffle(number seed)

This action shuffles the values in the array randomly. In this version, a seed for a random number generator is used.

Parameters

  • number seed: The seed for the random number generator

Example

use Libraries.Containers.Array
constant integer max = 20
Array<integer> values
i = 0
repeat while i < max
    values:Add(i)
    i = i + 1
end

values:Shuffle(0) //a random seed of 0

i = 0
repeat while i < max
    output values:Get(i)
    i = i + 1
end

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

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

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.

Parameters

Example

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(compare)

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.

Parameters

Example

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, temp)