1ArrayLabels(3)                     OCamldoc                     ArrayLabels(3)
2
3
4

NAME

6       ArrayLabels - Array operations.
7

Module

9       Module   ArrayLabels
10

Documentation

12       Module ArrayLabels
13        : sig end
14
15
16       Array operations.
17
18
19
20
21
22
23       val length : 'a array -> int
24
25       Return the length (number of elements) of the given array.
26
27
28
29       val get : 'a array -> int -> 'a
30
31
32       Array.get a n returns the element number n of array a .  The first ele‐
33       ment has number 0.  The last element has number Array.length a  -  1  .
34       You can also write a.(n) instead of Array.get a n .
35
36       Raise  Invalid_argument index out of bounds if n is outside the range 0
37       to (Array.length a - 1) .
38
39
40
41       val set : 'a array -> int -> 'a -> unit
42
43
44       Array.set a n x modifies array a in place, replacing element  number  n
45       with x .  You can also write a.(n) <- x instead of Array.set a n x .
46
47       Raise  Invalid_argument index out of bounds if n is outside the range 0
48       to Array.length a - 1 .
49
50
51
52       val make : int -> 'a -> 'a array
53
54
55       Array.make n x returns a fresh array of length n , initialized with x .
56       All  the elements of this new array are initially physically equal to x
57       (in the sense of the == predicate).  Consequently, if x is mutable,  it
58       is  shared among all elements of the array, and modifying x through one
59       of the array entries will modify all other entries at the same time.
60
61       Raise Invalid_argument if n < 0 or n > Sys.max_array_length .   If  the
62       value  of  x  is a floating-point number, then the maximum size is only
63       Sys.max_array_length / 2 .
64
65
66
67       val create : int -> 'a -> 'a array
68
69       Deprecated.
70
71       Array.create is an alias for Array.make .
72
73
74
75       val init : int -> f:(int -> 'a) -> 'a array
76
77
78       Array.init n f returns a fresh array of length n , with element  number
79       i  initialized  to  the result of f i .  In other terms, Array.init n f
80       tabulates the results of f applied to the integers 0 to n-1 .
81
82       Raise Invalid_argument if n < 0 or n > Sys.max_array_length .   If  the
83       return   type   of  f  is  float  ,  then  the  maximum  size  is  only
84       Sys.max_array_length / 2 .
85
86
87
88       val make_matrix : dimx:int -> dimy:int -> 'a -> 'a array array
89
90
91       Array.make_matrix dimx dimy e returns a two-dimensional array (an array
92       of  arrays)  with  first dimension dimx and second dimension dimy . All
93       the elements of this new matrix are initially physically equal to  e  .
94       The  element  (  x,y  )  of  a  matrix  m is accessed with the notation
95       m.(x).(y) .
96
97       Raise Invalid_argument if dimx or dimy  is  negative  or  greater  than
98       Sys.max_array_length  .   If the value of e is a floating-point number,
99       then the maximum size is only Sys.max_array_length / 2 .
100
101
102
103       val create_matrix : dimx:int -> dimy:int -> 'a -> 'a array array
104
105       Deprecated.
106
107       Array.create_matrix is an alias for Array.make_matrix .
108
109
110
111       val append : 'a array -> 'a array -> 'a array
112
113
114       Array.append v1 v2 returns a fresh array containing  the  concatenation
115       of the arrays v1 and v2 .
116
117
118
119       val concat : 'a array list -> 'a array
120
121       Same as Array.append , but concatenates a list of arrays.
122
123
124
125       val sub : 'a array -> pos:int -> len:int -> 'a array
126
127
128       Array.sub  a start len returns a fresh array of length len , containing
129       the elements number start to start + len - 1 of array a .
130
131       Raise Invalid_argument Array.sub if start and len do  not  designate  a
132       valid  subarray  of a ; that is, if start < 0 , or len < 0 , or start +
133       len > Array.length a .
134
135
136
137       val copy : 'a array -> 'a array
138
139
140       Array.copy a returns a copy of a , that is, a  fresh  array  containing
141       the same elements as a .
142
143
144
145       val fill : 'a array -> pos:int -> len:int -> 'a -> unit
146
147
148       Array.fill a ofs len x modifies the array a in place, storing x in ele‐
149       ments number ofs to ofs + len - 1 .
150
151       Raise Invalid_argument Array.fill if ofs and len  do  not  designate  a
152       valid subarray of a .
153
154
155
156       val  blit  : src:'a array -> src_pos:int -> dst:'a array -> dst_pos:int
157       -> len:int -> unit
158
159
160       Array.blit v1 o1 v2 o2 len copies len elements from array v1 , starting
161       at element number o1 , to array v2 , starting at element number o2 . It
162       works correctly even if v1 and v2 are the same array,  and  the  source
163       and destination chunks overlap.
164
165       Raise  Invalid_argument  Array.blit  if  o1  and len do not designate a
166       valid subarray of v1 , or if o2 and len do not designate a valid subar‐
167       ray of v2 .
168
169
170
171       val to_list : 'a array -> 'a list
172
173
174       Array.to_list a returns the list of all the elements of a .
175
176
177
178       val of_list : 'a list -> 'a array
179
180
181       Array.of_list l returns a fresh array containing the elements of l .
182
183
184
185       val iter : f:('a -> unit) -> 'a array -> unit
186
187
188       Array.iter  f  a  applies function f in turn to all the elements of a .
189       It is equivalent to f a.(0); f a.(1); ...; f a.(Array.length a - 1); ()
190       .
191
192
193
194       val map : f:('a -> 'b) -> 'a array -> 'b array
195
196
197       Array.map  f a applies function f to all the elements of a , and builds
198       an array with the results returned by f : [| f a.(0); f a.(1);  ...;  f
199       a.(Array.length a - 1) |] .
200
201
202
203       val iteri : f:(int -> 'a -> unit) -> 'a array -> unit
204
205       Same  as  Array.iter  , but the function is applied to the index of the
206       element as first argument, and the element itself as second argument.
207
208
209
210       val mapi : f:(int -> 'a -> 'b) -> 'a array -> 'b array
211
212       Same as Array.map , but the function is applied to  the  index  of  the
213       element as first argument, and the element itself as second argument.
214
215
216
217       val fold_left : f:('a -> 'b -> 'a) -> init:'a -> 'b array -> 'a
218
219
220       Array.fold_left  f  x  a  computes  f  (...  (f (f x a.(0)) a.(1)) ...)
221       a.(n-1) , where n is the length of the array a .
222
223
224
225       val fold_right : f:('b -> 'a -> 'a) -> 'b array -> init:'a -> 'a
226
227
228       Array.fold_right f a x computes f a.(0) (f a.(1) ( ...  (f  a.(n-1)  x)
229       ...))  , where n is the length of the array a .
230
231
232
233
234       === Iterators on two arrays ===
235
236
237       val iter2 : f:('a -> 'b -> unit) -> 'a array -> 'b array -> unit
238
239
240       Array.iter2  f  a b applies function f to all the elements of a and b .
241       Raise Invalid_argument if the arrays are not the same size.
242
243
244       Since 4.05.0
245
246
247
248       val map2 : f:('a -> 'b -> 'c) -> 'a array -> 'b array -> 'c array
249
250
251       Array.map2 f a b applies function f to all the elements of a  and  b  ,
252       and  builds an array with the results returned by f : [| f a.(0) b.(0);
253       ...; f a.(Array.length a  -  1)  b.(Array.length  b  -  1)|]  .   Raise
254       Invalid_argument if the arrays are not the same size.
255
256
257       Since 4.05.0
258
259
260
261
262       === Array scanning ===
263
264
265       val exists : f:('a -> bool) -> 'a array -> bool
266
267
268       Array.exists  p  [|a1;  ...; an|] checks if at least one element of the
269       array satisfies the predicate p . That is, it returns (p a1) || (p  a2)
270       || ... || (p an) .
271
272
273       Since 4.03.0
274
275
276
277       val for_all : f:('a -> bool) -> 'a array -> bool
278
279
280       Array.for_all  p  [|a1;  ...;  an|] checks if all elements of the array
281       satisfy the predicate p . That is, it returns (p a1) && (p a2)  &&  ...
282       && (p an) .
283
284
285       Since 4.03.0
286
287
288
289       val mem : 'a -> set:'a array -> bool
290
291
292       mem x a is true if and only if x is equal to an element of a .
293
294
295       Since 4.03.0
296
297
298
299       val memq : 'a -> set:'a array -> bool
300
301       Same  as  Array.mem  , but uses physical equality instead of structural
302       equality to compare list elements.
303
304
305       Since 4.03.0
306
307
308
309       val create_float : int -> float array
310
311
312       Array.create_float n returns a fresh float array of  length  n  ,  with
313       uninitialized data.
314
315
316       Since 4.03
317
318
319
320       val make_float : int -> float array
321
322       Deprecated.
323
324       Array.make_float is an alias for Array.create_float .
325
326
327
328
329       === Sorting ===
330
331
332       val sort : cmp:('a -> 'a -> int) -> 'a array -> unit
333
334       Sort  an  array in increasing order according to a comparison function.
335       The comparison function must return  0  if  its  arguments  compare  as
336       equal, a positive integer if the first is greater, and a negative inte‐
337       ger if the first is smaller (see below for a  complete  specification).
338       For example, Pervasives.compare is a suitable comparison function, pro‐
339       vided there are no floating-point NaN values in the data.  After  call‐
340       ing  Array.sort  ,  the  array  is sorted in place in increasing order.
341       Array.sort is guaranteed to run in constant heap space  and  (at  most)
342       logarithmic stack space.
343
344       The  current  implementation uses Heap Sort.  It runs in constant stack
345       space.
346
347       Specification of the comparison function: Let a be the  array  and  cmp
348       the comparison function.  The following must be true for all x, y, z in
349       a :
350
351       - cmp x y > 0 if and only if cmp y x < 0
352
353       -  if cmp x y >= 0 and cmp y z >= 0 then cmp x z >= 0
354
355       When Array.sort returns,  a  contains  the  same  elements  as  before,
356       reordered in such a way that for all i and j valid indices of a :
357
358       - cmp a.(i) a.(j) >= 0 if and only if i >= j
359
360
361
362
363       val stable_sort : cmp:('a -> 'a -> int) -> 'a array -> unit
364
365       Same  as  Array.sort  , but the sorting algorithm is stable (i.e.  ele‐
366       ments that compare equal are kept in  their  original  order)  and  not
367       guaranteed to run in constant heap space.
368
369       The  current  implementation uses Merge Sort. It uses n/2 words of heap
370       space, where n is the length of the array.  It is usually  faster  than
371       the current implementation of Array.sort .
372
373
374
375       val fast_sort : cmp:('a -> 'a -> int) -> 'a array -> unit
376
377       Same  as Array.sort or Array.stable_sort , whichever is faster on typi‐
378       cal input.
379
380
381
382
383
3842018-04-14                          source:                     ArrayLabels(3)
Impressum