|
| 1 | +; |
| 2 | +; Array library documentation |
| 3 | +; |
| 4 | +; (c) 2011 - Fantaisie Software |
| 5 | +; |
| 6 | + |
| 7 | +@Library Array |
| 8 | + |
| 9 | +@Overview |
| 10 | + |
| 11 | + Arrays are structures to store indexed elements. Unlike |
| 12 | + a @LibraryLink "List" "list" or a @LibraryLink "Map" "map", the |
| 13 | + elements are allocated in a contiguous manner in memory. Therefore, it's |
| 14 | + not possible to easily insert or remove an element. On other hand, |
| 15 | + it provides a very fast direct access to a random element. |
| 16 | +@LineBreak |
| 17 | +@LineBreak |
| 18 | + To work with Arrays, they have to be declared first. This could be |
| 19 | + done with the keyword @ReferenceLink "dim" "Dim". |
| 20 | +@LineBreak |
| 21 | +@LineBreak |
| 22 | + Arrays can be sorted using @@SortArray or @@SortStructuredArray, and can also |
| 23 | + be randomized using @@RandomizeArray. |
| 24 | + |
| 25 | +@CommandList |
| 26 | + |
| 27 | +@ExampleFile All Array.pb |
| 28 | + |
| 29 | +@SupportedOS |
| 30 | + |
| 31 | +;-------------------------------------------------------------------------------------------------------- |
| 32 | + |
| 33 | +@Function Result = ArraySize(Array() [, Dimension]) |
| 34 | + |
| 35 | +@Description |
| 36 | + Returns the size of the array, as specified with @Keyword Dim or @Keyword ReDim. |
| 37 | + |
| 38 | +@Parameter "Array()" |
| 39 | + The array to get the size from. |
| 40 | + |
| 41 | +@OptionalParameter "Dimension" |
| 42 | + For multidimensional arrays, this parameter can be specified to get a specific dimension size. |
| 43 | + The first dimension starts from 1. |
| 44 | + |
| 45 | +@ReturnValue |
| 46 | + Returns the size of the array dimension. |
| 47 | + If the array isn't yet declared (or its allocation has failed), it will return -1. |
| 48 | + |
| 49 | +@Example |
| 50 | + |
| 51 | +@Code |
| 52 | + Dim MyArray.l(10) |
| 53 | + Debug ArraySize(MyArray()) ; will print '10' |
| 54 | + |
| 55 | + Dim MultiArray.l(10, 20, 30) |
| 56 | + Debug ArraySize(MultiArray(), 2) ; will print '20' |
| 57 | +@EndCode |
| 58 | + |
| 59 | +@Example |
| 60 | + |
| 61 | +@Code |
| 62 | + Dim Test.q(99999999999999999) |
| 63 | + |
| 64 | + If ArraySize(Test()) <> -1 |
| 65 | + Test(12345) = 123 ; everything fine |
| 66 | + Else |
| 67 | + Debug "Array 'Test()' couldn't be initialized." |
| 68 | + EndIf |
| 69 | +@EndCode |
| 70 | + |
| 71 | +@SeeAlso |
| 72 | + @@ListSize, @@MapSize |
| 73 | + |
| 74 | +@SupportedOS |
| 75 | + |
| 76 | +;-------------------------------------------------------------------------------------------------------- |
| 77 | + |
| 78 | +@Function Result = CopyArray(SourceArray(), DestinationArray()) |
| 79 | + |
| 80 | +@Description |
| 81 | + Copy every elements of 'SourceArray()' into 'DestinationArray()'. |
| 82 | + After a successful copy, the two arrays are identical. The arrays must have the |
| 83 | + same number of dimensions. |
| 84 | + |
| 85 | +@Parameter "SourceArray()" |
| 86 | + The array to copy from. |
| 87 | + |
| 88 | +@Parameter "DestinationArray()" |
| 89 | + The array to copy to. Every element previously found in this array will be deleted. |
| 90 | + This array must be of the same type (native or structured) and the same |
| 91 | + number of dimensions of the source array. |
| 92 | + |
| 93 | +@ReturnValue |
| 94 | + Returns nonzero if the copy succeeded or zero if it failed. |
| 95 | + |
| 96 | +@Example |
| 97 | + |
| 98 | +@Code |
| 99 | + Dim Numbers(5) |
| 100 | + Dim NumbersCopy(10) |
| 101 | + |
| 102 | + Numbers(0) = 128 |
| 103 | + Numbers(5) = 256 |
| 104 | + |
| 105 | + Debug "Array size before copy: "+Str(ArraySize(NumbersCopy())) ; will print 10 |
| 106 | + |
| 107 | + CopyArray(Numbers(), NumbersCopy()) |
| 108 | + |
| 109 | + Debug "Array size after copy: "+Str(ArraySize(NumbersCopy())) ; will print 5 |
| 110 | + Debug NumbersCopy(0) |
| 111 | + Debug NumbersCopy(5) |
| 112 | +@EndCode |
| 113 | + |
| 114 | +@SeeAlso |
| 115 | + @@CopyList, @@CopyMap |
| 116 | + |
| 117 | + |
| 118 | +@SupportedOS |
| 119 | + |
| 120 | +;-------------------------------------------------------------------------------------------------------- |
| 121 | + |
| 122 | +@Function FreeArray(Array()) |
| 123 | + |
| 124 | +@Description |
| 125 | + Free the specified 'Array()' and release all its associated memory. To access it again |
| 126 | + @ReferenceLink "dim" "Dim" has to be called. |
| 127 | + |
| 128 | +@Parameter "Array()" |
| 129 | + The array to free. |
| 130 | + |
| 131 | +@NoReturnValue |
| 132 | + |
| 133 | +@SeeAlso |
| 134 | + @@FreeList, @@FreeMap |
| 135 | + |
| 136 | +@SupportedOS |
0 commit comments