1ArrayLabels(3)                   OCaml library                  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
24       val length : 'a array -> int
25
26       Return the length (number of elements) of the given array.
27
28
29
30
31       val get : 'a array -> int -> 'a
32
33
34       Array.get a n returns the element number n of array a .  The first ele‐
35       ment has number 0.  The last element has number Array.length a  -  1  .
36       Raise  Invalid_argument  Array.get  if  n  is  outside  the  range 0 to
37       (Array.length a - 1) .  You can also write a.(n) instead of Array.get a
38       n .
39
40
41
42
43       val set : 'a array -> int -> 'a -> unit
44
45
46       Array.set  a  n x modifies array a in place, replacing element number n
47       with x .
48
49       Raise Invalid_argument Array.set  if  n  is  outside  the  range  0  to
50       Array.length  a  -  1  .   You  can  also  write  a.(n) <- x instead of
51       Array.set a n x .
52
53
54
55
56       val make : int -> 'a -> 'a array
57
58
59       Array.make n x returns a fresh array of length n , initialized with x .
60       All  the elements of this new array are initially physically equal to x
61       (in the sense of the == predicate).  Consequently, if x is mutable,  it
62       is  shared among all elements of the array, and modifying x through one
63       of the array entries will modify all other entries at the same time.
64
65       Raise Invalid_argument if n < 0 or n > Sys.max_array_length .   If  the
66       value  of  x  is a floating-point number, then the maximum size is only
67       Sys.max_array_length / 2 .
68
69
70
71
72       val create : int -> 'a -> 'a array
73
74       Deprecated.
75
76       Array.create is an alias for ArrayLabels.make .
77
78
79
80
81       val init : int -> f:(int -> 'a) -> 'a array
82
83
84       Array.init n f returns a fresh array of length n , with element  number
85       i  initialized  to  the result of f i .  In other terms, Array.init n f
86       tabulates the results of f applied to the integers 0 to n-1 .
87
88
89
90
91       val make_matrix : dimx:int -> dimy:int -> 'a -> 'a array array
92
93
94       Array.make_matrix dimx dimy e returns a two-dimensional array (an array
95       of  arrays)  with  first dimension dimx and second dimension dimy . All
96       the elements of this new matrix are initially physically equal to  e  .
97       The  element  (  x,y  )  of  a  matrix  m is accessed with the notation
98       m.(x).(y) .
99
100       Raise Invalid_argument if dimx or dimy is less than 1 or  greater  than
101       Sys.max_array_length  .   If the value of e is a floating-point number,
102       then the maximum size is only Sys.max_array_length / 2 .
103
104
105
106
107       val create_matrix : dimx:int -> dimy:int -> 'a -> 'a array array
108
109       Deprecated.
110
111       Array.create_matrix is an alias for ArrayLabels.make_matrix .
112
113
114
115
116       val append : 'a array -> 'a array -> 'a array
117
118
119       Array.append v1 v2 returns a fresh array containing  the  concatenation
120       of the arrays v1 and v2 .
121
122
123
124
125       val concat : 'a array list -> 'a array
126
127       Same as Array.append , but concatenates a list of arrays.
128
129
130
131
132       val sub : 'a array -> pos:int -> len:int -> 'a array
133
134
135       Array.sub  a start len returns a fresh array of length len , containing
136       the elements number start to start + len - 1 of array a .
137
138       Raise Invalid_argument Array.sub if start and len do  not  designate  a
139       valid  subarray  of a ; that is, if start < 0 , or len < 0 , or start +
140       len > Array.length a .
141
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
154       val fill : 'a array -> pos:int -> len:int -> 'a -> unit
155
156
157       Array.fill a ofs len x modifies the array a in place, storing x in ele‐
158       ments number ofs to ofs + len - 1 .
159
160       Raise Invalid_argument Array.fill if ofs and len  do  not  designate  a
161       valid subarray of a .
162
163
164
165
166       val  blit  : src:'a array -> src_pos:int -> dst:'a array -> dst_pos:int
167       -> len:int -> unit
168
169
170       Array.blit v1 o1 v2 o2 len copies len elements from array v1 , starting
171       at element number o1 , to array v2 , starting at element number o2 . It
172       works correctly even if v1 and v2 are the same array,  and  the  source
173       and destination chunks overlap.
174
175       Raise  Invalid_argument  Array.blit  if  o1  and len do not designate a
176       valid subarray of v1 , or if o2 and len do not designate a valid subar‐
177       ray of v2 .
178
179
180
181
182       val to_list : 'a array -> 'a list
183
184
185       Array.to_list a returns the list of all the elements of a .
186
187
188
189
190       val of_list : 'a list -> 'a array
191
192
193       Array.of_list l returns a fresh array containing the elements of l .
194
195
196
197
198       val iter : f:('a -> unit) -> 'a array -> unit
199
200
201       Array.iter  f  a  applies function f in turn to all the elements of a .
202       It is equivalent to f a.(0); f a.(1); ...; f a.(Array.length a - 1); ()
203       .
204
205
206
207
208       val map : f:('a -> 'b) -> 'a array -> 'b array
209
210
211       Array.map  f a applies function f to all the elements of a , and builds
212       an array with the results returned by f : [| f a.(0); f a.(1);  ...;  f
213       a.(Array.length a - 1) |] .
214
215
216
217
218       val iteri : f:(int -> 'a -> unit) -> 'a array -> unit
219
220       Same  as ArrayLabels.iter , but the function is applied to the index of
221       the element as first argument, and the element itself as  second  argu‐
222       ment.
223
224
225
226
227       val mapi : f:(int -> 'a -> 'b) -> 'a array -> 'b array
228
229       Same  as  ArrayLabels.map , but the function is applied to the index of
230       the element as first argument, and the element itself as  second  argu‐
231       ment.
232
233
234
235
236       val fold_left : f:('a -> 'b -> 'a) -> init:'a -> 'b array -> 'a
237
238
239       Array.fold_left  f  x  a  computes  f  (...  (f (f x a.(0)) a.(1)) ...)
240       a.(n-1) , where n is the length of the array a .
241
242
243
244
245       val fold_right : f:('a -> 'b -> 'b) -> 'a array -> init:'b -> 'b
246
247
248       Array.fold_right f a x computes f a.(0) (f a.(1) ( ...  (f  a.(n-1)  x)
249       ...))  , where n is the length of the array a .
250
251
252
253
254
255       === Sorting ===
256
257
258       val sort : cmp:('a -> 'a -> int) -> 'a array -> unit
259
260       Sort  an  array in increasing order according to a comparison function.
261       The comparison function must return  0  if  its  arguments  compare  as
262       equal, a positive integer if the first is greater, and a negative inte‐
263       ger if the first is smaller.  For example, the Pervasives.compare func‐
264       tion is a suitable comparison function.  After calling Array.sort , the
265       array is sorted in place in increasing order.  Array.sort is guaranteed
266       to run in constant heap space and logarithmic stack space.
267
268       The  current  implementation uses Heap Sort.  It runs in constant stack
269       space.
270
271
272
273
274       val stable_sort : cmp:('a -> 'a -> int) -> 'a array -> unit
275
276       Same as ArrayLabels.sort , but the sorting algorithm is stable and  not
277       guaranteed to use a fixed amount of heap memory.  The current implemen‐
278       tation is Merge Sort. It uses n/2 words of heap space, where n  is  the
279       length  of  the array.  It is faster than the current implementation of
280       ArrayLabels.sort .
281
282
283
284
285       val fast_sort : cmp:('a -> 'a -> int) -> 'a array -> unit
286
287       Same as Array.sort or Array.stable_sort , whichever is faster on  typi‐
288       cal input.
289
290
291
292
293
294
295OCamldoc                          2007-05-24                    ArrayLabels(3)
Impressum