1StdLabels.Array(3)               OCaml library              StdLabels.Array(3)
2
3
4

NAME

6       StdLabels.Array - no description
7

Module

9       Module   StdLabels.Array
10

Documentation

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