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