1Stdlib.ArrayLabels(3)            OCaml library           Stdlib.ArrayLabels(3)
2
3
4

NAME

6       Stdlib.ArrayLabels - no description
7

Module

9       Module   Stdlib.ArrayLabels
10

Documentation

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