Arrays Package
The SparForte built-in arrays package provides subprograms to manipulate
array variables or types. This includes determining the size of the array,
sorting the array or moving the items in the array.
GCC Ada Equivalent : array attributes, GNAT sort packages
arrays.bubble_sort( a )
Bubble sort the array, treating the elements as strings or numbers
depending on the element type.
Example
arrays.bubble_sort( sales_array );
Parameters
Param
Mode
Type
Default
Description
a
in out
any array type
required
the array to sort
Exceptions
-
See Also
arrays.bubble_sort_descending arrays.heap_sort arrays.heap_sort_descending
Compare With
Ada: GNAT.Bubble_Sort PHP: sort
arrays.bubble_sort_descending( a )
Bubble sort the array in descending order, treating the elements as
strings or numbers depending on the element type.
Example
arrays.bubble_sort_descending( sales_array );
Parameters
Param
Mode
Type
Default
Description
a
in out
any array type
required
the array to sort
Exceptions
-
See Also
arrays.bubble_sort arrays.heap_sort arrays.heap_sort_descending
Compare With
Ada: Uses GNAT.Bubble_Sort PHP: rsort
i := arrays.first( a )
Return the first (lowest) index of the array.
Example
i := arrays.first( sales_array );
Parameters
Param
Mode
Type
Default
Description
a
in
array type
required
the array with the index
i
return value
enumerated or numeric
required
the array's minimum bound
Exceptions
-
See Also
arrays.last
Compare With
Ada: 'first attribute
arrays.heap_sort( a )
Heap sort the array, treating the elements as
strings or numbers depending on the element type.
Example
arrays.heap_sort( sales_array );
Parameters
Param
Mode
Type
Default
Description
a
in out
any array type
required
the array to sort
Exceptions
-
See Also
arrays.bubble_sort arrays.bubble_sort_descending arrays.heap_sort_descending
Compare With
Ada: Uses GNAT.Heap_Sort PHP: sort
arrays.heap_sort_descending( a )
Heap sort the array in descending order, treating the elements as
strings or numbers depending on the element type.
Example
arrays.heap_sort_descending( sales_array );
Parameters
Param
Mode
Type
Default
Description
a
in out
any array type
required
the array to sort
Exceptions
-
See Also
arrays.bubble_sort arrays.bubble_sort_descending arrays.heap_sort
Compare With
Ada: GNAT.Heap_Sort PHP: rsort
i := arrays.last( a )
Return the last (highest) index of the array.
Example
i := arrays.last( sales_array );
Parameters
Param
Mode
Type
Default
Description
a
in
array type
required
the array with the index
i
return value
enumerated or numeric
required
the array's maximum bound
Exceptions
-
See Also
arrays.first
Compare With
Ada: 'last attribute
n := arrays.length( a )
Return the number of elements in the array (last index - first index + 1).
Example
n := arrays.length( sales_array );
Parameters
Param
Mode
Type
Default
Description
a
in
array type
required
the array to examine
n
return value
natural
required
the number of elements in the array
Exceptions
-
See Also
strings.length
Compare With
Ada: 'length attribute PHP: count
arrays.flip( a )
Reverse the order of the elements in the array, moving the last element
to the first position and the first element to the last position. (Prior to
version 1.1, this was arrays.reverse but was renamed to avoid a conflict with the Ada
reserved word "reverse".)
Example
arrays.flip( backwards_array );
Parameters
Param
Mode
Type
Default
Description
a
in out
any array type
required
the array to sort
Exceptions
-
See Also
-
Compare With
Ada: N/A PHP: array_reverse
arrays.rotate_left( a )
Move all elements of the array one element toward the first position, moving
the first element to the last position.
Example
arrays.rotate_left( work_queue );
Parameters
Param
Mode
Type
Default
Description
a
in out
any array type
required
the array to rotate
Exceptions
-
See Also
arrays.rotate_right arrays.shift_left arrays.shift_right
Compare With
Ada: N/A
arrays.rotate_right( a )
Move all elements of the array one element toward the last position, moving
the last element to the first position.
Example
arrays.rotate_right( work_queue );
Parameters
Param
Mode
Type
Default
Description
a
in out
any array type
required
the array to sort
Exceptions
-
See Also
arrays.rotate_left arrays.shift_left arrays.shift_right
Compare With
Ada: N/A
arrays.shift_left( a )
Move all elements of the array one element toward the first element,
overwriting the first element.
Example
arrays.shift_left( work_stack );
Parameters
Param
Mode
Type
Default
Description
a
in out
any array type
required
the array to rotate
Exceptions
-
See Also
arrays.rotate_left arrays.rotate_right arrays.shift_right
Compare With
Ada: N/A PHP: array_pop, array_shift
arrays.shift_right( a )
Move all elements of the array one element toward the last element,
overwriting the last element.
Example
arrays.shift_right( work_stack );
Parameters
Param
Mode
Type
Default
Description
a
in out
any array type
required
the array to rotate
Exceptions
-
See Also
arrays.rotate_left arrays.rotate_right arrays.shift_left
Compare With
Ada: N/A PHP: array_push, array_unshift
arrays.shuffle( a )
arrays.to_array( a, s )
arrays.to_json( s, a )