|
This part of the guide contains detailed descriptions of the
BUSH built-in packages.
4.14 Arrays Package
The arrays package provides general routines pretaining to BUSH arrays. 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
i := 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 );
Ada Equivalent: Uses GNAT.Bubble_Sort.
PHP Equivalent: sort
See Also: arrays.bubble_sort_descending, arrays.heap_sort, arrays.heap_sort_descending
Parameters:
| a |
in out |
any array type |
required |
the array to 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 );
Ada Equivalent: Uses GNAT.Bubble_Sort.
PHP Equivalent: rsort
See Also: arrays.bubble_sort, arrays.heap_sort, arrays.heap_sort_descending
Parameters:
| a |
in out |
any array type |
required |
the array to sort |
|
i := arrays.first( a )
Return the first (lowest) index of the array.
Example: i := arrays.first( sales_array );
Ada Equivalent: 'first attribute
See Also: arrays.last
Parameters:
| a |
in |
array type |
required |
the array with the index |
| i |
return value |
enumerated or numeric |
required |
the array's first bound |
|
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 );
Ada Equivalent: Uses GNAT.Heap_Sort.
PHP Equivalent: sort
See Also: arrays.bubble_sort, arrays.bubble_sort_descending, arrays.heap_sort_descending
Parameters:
| a |
in out |
any array type |
required |
the array to 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 );
Ada Equivalent: Uses GNAT.Heap_Sort.
PHP Equivalent: rsort
See Also: arrays.bubble_sort, arrays.bubble_sort_descending, arrays.heap_sort
Parameters:
| a |
in out |
any array type |
required |
the array to sort |
|
i := arrays.last( a )
Return the last (highest) index of the arrays
Example: i := arrays.last( sales_array );
Ada Equivalent: 'last attribute
See Also: arrays.first
Parameters:
| a |
in |
array type |
required |
the array with the index |
| i |
return value |
enumerated or numeric |
required |
the array's last bound |
|
n := arrays.length( a )
Return the number of elements in the array (last index - first index + 1).
Example: n := arrays.length( sales_array );
Ada Equivalent: 'length attribute
PHP Equivalent: count
See Also: strings.length
Parameters:
| a |
in |
array type |
required |
the array to examine |
| n |
return value |
natural |
required |
the number of elements in the array |
|
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. (This used
to be arrays.reverse but was renamed to avoid a conflict with the Ada
reserved word "reverse".)
Example: arrays.flip( backwards_array );
Ada Equivalent: N/A
PHP Equivalent: array_reverse
Parameters:
| a |
in out |
any array type |
required |
the array to reverse/flip |
|
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 );
Ada Equivalent: N/A
See Also: arrays.rotate_right, arrays.shift_left, arrays.shift_right
Parameters:
| a |
in out |
any array type |
required |
the array to rotate |
|
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 );
Ada Equivalent: N/A
See Also: arrays.rotate_left, arrays.shift_left, arrays.shift_right
Parameters:
| a |
in out |
any array type |
required |
the array to rotate |
|
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 );
Ada Equivalent: N/A
PHP Equivalent: array_pop, array_shift
See Also: arrays.rotate_left, arrays.rotate_right, arrays.shift_right
Parameters:
| a |
in out |
any array type |
required |
the array to rotate |
|
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 );
Ada Equivalent: N/A
PHP Equivalent: array_push, array_unshift
See Also: arrays.rotate_left, arrays.rotate_right, arrays.shift_left
Parameters:
| a |
in out |
any array type |
required |
the array to rotate |
|
arrays.shuffle( a )
Randomize the elements of the array.
Example: arrays.shuffle( playing_card_array );
Ada Equivalent: N/A
PHP Equivalent: shuffle
Parameters:
| a |
in out |
any array type |
required |
the array to shuffle |
|
Back to Top
|