14
14
15
15
(* * Array operations. *)
16
16
17
- (* * Return the length (number of elements) of the given array. *)
18
17
external length : 'a array -> int = " %array_length"
18
+ (* * Return the length (number of elements) of the given array. *)
19
19
20
+ external get : 'a array -> int -> 'a = " %array_safe_get"
20
21
(* * [Array.get a n] returns the element number [n] of array [a].
21
22
The first element has number 0.
22
23
The last element has number [Array.length a - 1].
23
24
24
25
Raise [Invalid_argument "Array.get"] if [n] is outside the range
25
26
0 to [(Array.length a - 1)].
26
27
You can also write [a.(n)] instead of [Array.get a n]. *)
27
- external get : 'a array -> int -> 'a = " %array_safe_get"
28
28
29
+ external set : 'a array -> int -> 'a -> unit = " %array_safe_set"
29
30
(* * [Array.set a n x] modifies array [a] in place, replacing
30
31
element number [n] with [x].
31
32
32
33
Raise [Invalid_argument "Array.set"] if [n] is outside the range
33
34
0 to [Array.length a - 1].
34
35
You can also write [a.(n) <- x] instead of [Array.set a n x]. *)
35
- external set : 'a array -> int -> 'a -> unit = " %array_safe_set"
36
36
37
+ external make : int -> 'a -> 'a array = " make_vect"
37
38
(* * [Array.make n x] returns a fresh array of length [n],
38
39
initialized with [x].
39
40
All the elements of this new array are initially
@@ -45,17 +46,17 @@ external set: 'a array -> int -> 'a -> unit = "%array_safe_set"
45
46
Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length].
46
47
If the value of [x] is a floating-point number, then the maximum
47
48
size is only [Sys.max_array_length / 2].*)
48
- external make : int -> 'a -> 'a array = " make_vect"
49
49
50
+ external create : int -> 'a -> 'a array = " make_vect"
50
51
(* * @deprecated [Array.create] is an alias for {!Array.make}. *)
51
- external create : int -> 'a -> 'a array = " make_vect"
52
52
53
+ val init : int -> (int -> 'a ) -> 'a array
53
54
(* * [Array.init n f] returns a fresh array of length [n],
54
55
with element number [i] initialized to the result of [f i].
55
56
In other terms, [Array.init n f] tabulates the results of [f]
56
57
applied to the integers [0] to [n-1]. *)
57
- val init : int -> (int -> 'a ) -> 'a array
58
58
59
+ val make_matrix : int -> int -> 'a -> 'a array array
59
60
(* * [Array.make_matrix dimx dimy e] returns a two-dimensional array
60
61
(an array of arrays) with first dimension [dimx] and
61
62
second dimension [dimy]. All the elements of this new matrix
@@ -67,38 +68,38 @@ val init: int -> (int -> 'a) -> 'a array
67
68
greater than [Sys.max_array_length].
68
69
If the value of [e] is a floating-point number, then the maximum
69
70
size is only [Sys.max_array_length / 2]. *)
70
- val make_matrix : int -> int -> 'a -> 'a array array
71
71
72
+ val create_matrix : int -> int -> 'a -> 'a array array
72
73
(* * @deprecated [Array.create_matrix] is an alias for {!Array.make_matrix}. *)
73
- val create_matrix : int -> int -> 'a -> 'a array array
74
74
75
+ val append : 'a array -> 'a array -> 'a array
75
76
(* * [Array.append v1 v2] returns a fresh array containing the
76
77
concatenation of the arrays [v1] and [v2]. *)
77
- val append : 'a array -> 'a array -> 'a array
78
78
79
+ val concat : 'a array list -> 'a array
79
80
(* * Same as [Array.append], but catenates a list of arrays. *)
80
- val concat : 'a array list -> 'a array
81
81
82
+ val sub : 'a array -> int -> int -> 'a array
82
83
(* * [Array.sub a start len] returns a fresh array of length [len],
83
84
containing the elements number [start] to [start + len - 1]
84
85
of array [a].
85
86
86
87
Raise [Invalid_argument "Array.sub"] if [start] and [len] do not
87
88
designate a valid subarray of [a]; that is, if
88
89
[start < 0], or [len < 0], or [start + len > Array.length a]. *)
89
- val sub : 'a array -> int -> int -> 'a array
90
90
91
+ val copy : 'a array -> 'a array
91
92
(* * [Array.copy a] returns a copy of [a], that is, a fresh array
92
93
containing the same elements as [a]. *)
93
- val copy : 'a array -> 'a array
94
94
95
+ val fill : 'a array -> int -> int -> 'a -> unit
95
96
(* * [Array.fill a ofs len x] modifies the array [a] in place,
96
97
storing [x] in elements number [ofs] to [ofs + len - 1].
97
98
98
99
Raise [Invalid_argument "Array.fill"] if [ofs] and [len] do not
99
100
designate a valid subarray of [a]. *)
100
- val fill : 'a array -> int -> int -> 'a -> unit
101
101
102
+ val blit : 'a array -> int -> 'a array -> int -> int -> unit
102
103
(* * [Array.blit v1 o1 v2 o2 len] copies [len] elements
103
104
from array [v1], starting at element number [o1], to array [v2],
104
105
starting at element number [o2]. It works correctly even if
@@ -108,49 +109,49 @@ val fill: 'a array -> int -> int -> 'a -> unit
108
109
Raise [Invalid_argument "Array.blit"] if [o1] and [len] do not
109
110
designate a valid subarray of [v1], or if [o2] and [len] do not
110
111
designate a valid subarray of [v2]. *)
111
- val blit : 'a array -> int -> 'a array -> int -> int -> unit
112
112
113
+ val to_list : 'a array -> 'a list
113
114
(* * [Array.to_list a] returns the list of all the elements of [a]. *)
114
- val to_list : 'a array -> 'a list
115
115
116
+ val of_list : 'a list -> 'a array
116
117
(* * [Array.of_list l] returns a fresh array containing the elements
117
118
of [l]. *)
118
- val of_list : 'a list -> 'a array
119
119
120
+ val iter : ('a -> unit ) -> 'a array -> unit
120
121
(* * [Array.iter f a] applies function [f] in turn to all
121
122
the elements of [a]. It is equivalent to
122
123
[f a.(0); f a.(1); ...; f a.(Array.length a - 1); ()]. *)
123
- val iter : ('a -> unit ) -> 'a array -> unit
124
124
125
+ val map : ('a -> 'b ) -> 'a array -> 'b array
125
126
(* * [Array.map f a] applies function [f] to all the elements of [a],
126
127
and builds an array with the results returned by [f]:
127
128
[[| f a.(0); f a.(1); ...; f a.(Array.length a - 1) |]]. *)
128
- val map : ('a -> 'b ) -> 'a array -> 'b array
129
129
130
+ val iteri : (int -> 'a -> unit ) -> 'a array -> unit
130
131
(* * Same as {!Array.iter}, but the
131
132
function is applied to the index of the element as first argument,
132
133
and the element itself as second argument. *)
133
- val iteri : (int -> 'a -> unit ) -> 'a array -> unit
134
134
135
+ val mapi : (int -> 'a -> 'b ) -> 'a array -> 'b array
135
136
(* * Same as {!Array.map}, but the
136
137
function is applied to the index of the element as first argument,
137
138
and the element itself as second argument. *)
138
- val mapi : (int -> 'a -> 'b ) -> 'a array -> 'b array
139
139
140
+ val fold_left : ('a -> 'b -> 'a ) -> 'a -> 'b array -> 'a
140
141
(* * [Array.fold_left f x a] computes
141
142
[f (... (f (f x a.(0)) a.(1)) ...) a.(n-1)],
142
143
where [n] is the length of the array [a]. *)
143
- val fold_left : ('a -> 'b -> 'a ) -> 'a -> 'b array -> 'a
144
144
145
+ val fold_right : ('b -> 'a -> 'a ) -> 'b array -> 'a -> 'a
145
146
(* * [Array.fold_right f a x] computes
146
147
[f a.(0) (f a.(1) ( ... (f a.(n-1) x) ...))],
147
148
where [n] is the length of the array [a]. *)
148
- val fold_right : ('b -> 'a -> 'a ) -> 'b array -> 'a -> 'a
149
149
150
150
151
151
(* * {2 Sorting} *)
152
152
153
153
154
+ val sort : ('a -> 'a -> int ) -> 'a array -> unit
154
155
(* * Sort an array in increasing order according to a comparison
155
156
function. The comparison function must return 0 if its arguments
156
157
compare as equal, a positive integer if the first is greater,
@@ -161,22 +162,20 @@ val fold_right: ('b -> 'a -> 'a) -> 'b array -> 'a -> 'a
161
162
[Array.sort] is guaranteed to run in constant heap space
162
163
and logarithmic stack space.
163
164
164
-
165
165
The current implementation uses Heap Sort. It runs in constant
166
166
stack space.
167
167
*)
168
- val sort : ('a -> 'a -> int ) -> 'a array -> unit ;;
169
168
169
+ val stable_sort : ('a -> 'a -> int ) -> 'a array -> unit
170
170
(* * Same as {!Array.sort}, but the sorting algorithm is stable and
171
171
not guaranteed to use a fixed amount of heap memory.
172
172
The current implementation is Merge Sort. It uses [n/2]
173
173
words of heap space, where [n] is the length of the array.
174
174
It is faster than the current implementation of {!Array.sort}.
175
175
*)
176
- val stable_sort : ('a -> 'a -> int ) -> 'a array -> unit ;;
177
176
178
177
(* */**)
179
178
(* * {2 Undocumented functions} *)
180
179
181
- external unsafe_get : 'a array -> int -> 'a = " %array_unsafe_get"
182
- external unsafe_set : 'a array -> int -> 'a -> unit = " %array_unsafe_set"
180
+ external unsafe_get : 'a array -> int -> 'a = " %array_unsafe_get"
181
+ external unsafe_set : 'a array -> int -> 'a -> unit = " %array_unsafe_set"
0 commit comments