[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

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 )

 

Randomize the elements of the array with a Fisher-Yates shuffle.

Example

arrays.shuffle( playing_card_array );

Parameters

Param Mode Type Default Description
a in out any array type required the array to shuffle

Exceptions

-

See Also

arrays.bubble_sort_descending
arrays.heap_sort
arrays.heap_sort_descending

Compare With

Ada: N/A
PHP: shuffle

arrays.to_array( a, s )

 

Decode a JSON string, storing the values in the array.

Example

s := "[32]";
arrays.to_array( a, s ); -- a(1) is 32

Parameters

Param Mode Type Default Description
a out an array type required the array to assign values to
s in json_string required the JSON expression

Exceptions

For more details and exceptions, see the Reference Manual section JSON and SparForte Types.

See Also

arrays.to_json
records.to_record
records.to_json
strings.to_string
strings.to_json

Compare With

Ada: N/A
PHP: json_decode

arrays.to_json( s, a )

 

Encode the array contents as a JSON string.

Example

a : array(1..1) of string := "apple";
arrays.to_json( s, a ); -- s is ["apple"]

Parameters

Param Mode Type Default Description
s out json_string required the JSON expression
a in an array type required the array to get values from

Exceptions

For more details and exceptions, see the Reference Manual section JSON and SparForte Types.

See Also

arrays.to_array
records.to_record
records.to_json
strings.to_string
strings.to_json

Compare With

Ada: N/A
PHP: json_encode

 
[Right Submenu]

 Summary

 arrays

 btree_io

 calendar

 cgi

 chains

 command_line

 db/ postgresql

 dbm

 directory_operations

 doubly_linked...

 dynamic_hash_...

 enums

 exceptions

 files

 gnat.cgi

 gnat.crc32

 hash_io

 lock_files

 memcache

 memcache.highread

 mysql

 mysqlm

 numerics

 os

 pen

 pen (OpenGL)

 records

 sound

 source_info

 stats

 strings

 System

 teams

 templates

 text_io

 units

[Back to Top] Back To Top [Small Forte Symbol]