Arrays
Arrays are containers of FISH variables where the inserted items are assigned and retrieved via an integer index. Arrays may be multidimensional. See Array Utilities for available methods.
Arrays are less flexible and perform less well than Lists or Maps. If very large amounts of data needs to be stored in multiple dimensions then array types may be the optimal choice, otherwise we suggest arrays be replaced with Lists whenever possible in older FISH code.
Arrays may be created using the array.create
library function.
The number of arguments give to this function indicate the array dimension, and the value of those arguments indicate the size in that dimension.
There is no limit to the number and size of the array dimensions, except memory capacity.
Array objects can be destroyed with the array.delete
intrinsic function.
It is not necessary to do this, array objects that are not referred to by any fish value will be automatically destroyed and their memory recovered.
Members of an array are FISH variables (except that there is no name associated with them), and are therefore governed by the same rules as symbol values. If a FISH symbol points to an array, array elements may be accessed by specifying an index in a parenthesis-enclosed list. For example:
var1 = abc(3, nn + 3, math.max(5, 6))
is a valid statement if abc is currently pointing to a three-dimensional array. Arrays may appear on both sides of an assignment, and arrays may be used as indices of other arrays.
Be aware that if abc currently points to an array, the statement:
abc = 0
will cause abc to become an integer whose value is zero. If no other symbol points to the array, all access to that array is lost and the array will be deleted automatically.
Arrays can be compared against each other with ==, <, > etc. If the structures are of the same type name then each member is compared in order.
Arrays are an iterable type. This means you can use it as the target of a loop foreach statement (see Loop ForEach and can be split (see Splitting). Each entry of the array is iterated with the left-most index changing first and the right-most index changing last.
As with most aggregate types, when the value is listed it will simply indicate that it is of type Array, give the size, and an unique ID number assigned to it. To see the contents of the array use the fish list contents
command. Be aware that for large multi-dimensional arrays this could be a considerable amount of data.
Was this helpful? ... | Itasca Software © 2024, Itasca | Updated: Aug 13, 2024 |