|
1 | 1 | (** Fixed-length, mutable vector of elements with O(1) [get] and [set] operations. *) |
2 | 2 |
|
3 | 3 | open! Import |
| 4 | +module Option = Option0 |
| 5 | +module List = List0.Constructors |
4 | 6 |
|
5 | 7 | module Definitions = struct |
6 | 8 | module type Public = sig |
7 | 9 | type 'a t |
8 | 10 |
|
9 | | - [%%rederive: |
10 | | - type nonrec 'a t = 'a t |
11 | | - [@@deriving |
12 | | - compare ~localize, equal ~localize, globalize, sexp ~stackify, sexp_grammar]] |
13 | | - |
14 | 11 | include Binary_searchable.S1 with type 'a t := 'a t |
15 | 12 |
|
16 | 13 | include |
17 | 14 | Indexed_container.S1_with_creators__base |
18 | 15 | with type 'a t := 'a t |
19 | | - and type 'a t__float64 := 'a t |
20 | | - and type 'a t__bits32 := 'a t |
21 | | - and type 'a t__bits64 := 'a t |
22 | | - and type 'a t__word := 'a t |
23 | | - and type 'a t__immediate := 'a t |
24 | | - and type 'a t__immediate64 := 'a t |
| 16 | + and type 'a t__float64 = 'a t |
| 17 | + and type 'a t__bits32 = 'a t |
| 18 | + and type 'a t__bits64 = 'a t |
| 19 | + and type 'a t__word = 'a t |
| 20 | + and type 'a t__immediate = 'a t |
| 21 | + and type 'a t__immediate64 = 'a t |
| 22 | + |
| 23 | + [%%template: |
| 24 | + [@@@kind k = (value, float64, bits32, bits64, word, immediate, immediate64)] |
| 25 | + |
| 26 | + [%%rederive: |
| 27 | + type nonrec 'a t = 'a t |
| 28 | + [@@kind k] |
| 29 | + [@@deriving compare ~localize, equal ~localize, sexp ~stackify, globalize]]] |
| 30 | + |
| 31 | + [%%rederive: type nonrec 'a t = 'a t [@@deriving sexp_grammar]] |
25 | 32 |
|
26 | 33 | include Indexed_container.S1_with_creators with type 'a t := 'a t |
27 | 34 | include Invariant.S1 with type 'a t := 'a t |
@@ -223,54 +230,58 @@ module Definitions = struct |
223 | 230 | val map2_exn : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t |
224 | 231 | val fold2_exn : 'a t -> 'b t -> init:'acc -> f:('acc -> 'a -> 'b -> 'acc) -> 'acc |
225 | 232 |
|
226 | | - (** [for_all2_exn t1 t2 ~f] fails if [length t1 <> length t2]. *) |
227 | | - val for_all2_exn : 'a t -> 'b t -> f:('a -> 'b -> bool) -> bool |
| 233 | + (** Modifies an array in place, applying [f] to every element of the array *) |
| 234 | + val map_inplace : 'a t -> f:('a -> 'a) -> unit |
228 | 235 |
|
229 | | - (** [exists2_exn t1 t2 ~f] fails if [length t1 <> length t2]. *) |
230 | | - val exists2_exn : 'a t -> 'b t -> f:('a -> 'b -> bool) -> bool |
| 236 | + [%%template: |
| 237 | + [@@@kind.default k1 = (value, float64, bits32, bits64, word, immediate, immediate64)] |
| 238 | + |
| 239 | + (** [find_exn f t] returns the first [a] in [t] for which [f t.(i)] is true. It raises |
| 240 | + [Stdlib.Not_found] or [Not_found_s] if there is no such [a]. *) |
| 241 | + val find_exn : 'a. 'a t -> f:('a -> bool) -> 'a |
231 | 242 |
|
232 | 243 | (** [swap arr i j] swaps the value at index [i] with that at index [j]. *) |
233 | | - val swap : 'a t -> int -> int -> unit |
| 244 | + val swap : 'a. 'a t -> int -> int -> unit |
234 | 245 |
|
235 | 246 | (** [rev_inplace t] reverses [t] in place. *) |
236 | | - val rev_inplace : 'a t -> unit |
| 247 | + val rev_inplace : 'a. 'a t -> unit |
237 | 248 |
|
238 | 249 | (** [rev t] returns a reversed copy of [t] *) |
239 | | - val rev : 'a t -> 'a t |
| 250 | + val rev : 'a. 'a t -> 'a t |
240 | 251 |
|
241 | 252 | (** [of_list_rev l] converts from list then reverses in place. *) |
242 | | - val of_list_rev : 'a list -> 'a t |
| 253 | + val of_list_rev : 'a. ('a List.t[@kind k1]) -> 'a t |
| 254 | + |
| 255 | + [@@@kind.default k2 = (value, float64, bits32, bits64, word, immediate, immediate64)] |
| 256 | + |
| 257 | + (** Returns the first evaluation of [f] that returns [Some]. Raises [Stdlib.Not_found] |
| 258 | + or [Not_found_s] if [f] always returns [None]. *) |
| 259 | + val find_map_exn : 'a 'b. 'a t -> f:('a -> ('b Option.t[@kind k2])) -> 'b |
| 260 | + |
| 261 | + (** [find_mapi_exn] is like [find_map_exn] but passes the index as an argument. *) |
| 262 | + val find_mapi_exn : 'a 'b. 'a t -> f:(int -> 'a -> ('b Option.t[@kind k2])) -> 'b |
243 | 263 |
|
244 | 264 | (** [of_list_map l ~f] is the same as [of_list (List.map l ~f)]. *) |
245 | | - val of_list_map : 'a list -> f:('a -> 'b) -> 'b t |
| 265 | + val of_list_map : 'a 'b. ('a List.t[@kind k1]) -> f:('a -> 'b) -> 'b t |
246 | 266 |
|
247 | 267 | (** [of_list_mapi l ~f] is the same as [of_list (List.mapi l ~f)]. *) |
248 | | - val of_list_mapi : 'a list -> f:(int -> 'a -> 'b) -> 'b t |
| 268 | + val of_list_mapi : 'a 'b. ('a List.t[@kind k1]) -> f:(int -> 'a -> 'b) -> 'b t |
249 | 269 |
|
250 | 270 | (** [of_list_rev_map l ~f] is the same as [of_list (List.rev_map l ~f)]. *) |
251 | | - val of_list_rev_map : 'a list -> f:('a -> 'b) -> 'b t |
| 271 | + val of_list_rev_map : 'a 'b. ('a List.t[@kind k1]) -> f:('a -> 'b) -> 'b t |
252 | 272 |
|
253 | 273 | (** [of_list_rev_mapi l ~f] is the same as [of_list (List.rev_mapi l ~f)]. *) |
254 | | - val of_list_rev_mapi : 'a list -> f:(int -> 'a -> 'b) -> 'b t |
255 | | - |
256 | | - (** Modifies an array in place, applying [f] to every element of the array *) |
257 | | - val map_inplace : 'a t -> f:('a -> 'a) -> unit |
| 274 | + val of_list_rev_mapi : 'a 'b. ('a List.t[@kind k1]) -> f:(int -> 'a -> 'b) -> 'b t |
258 | 275 |
|
259 | 276 | [%%template: |
260 | | - [@@@kind.default k1 = (value, float64, bits32, bits64, word, immediate, immediate64)] |
| 277 | + [@@@kind.default k1 k2] |
| 278 | + [@@@mode.default m = (global, local)] |
261 | 279 |
|
262 | | - (** [find_exn f t] returns the first [a] in [t] for which [f t.(i)] is true. It raises |
263 | | - [Stdlib.Not_found] or [Not_found_s] if there is no such [a]. *) |
264 | | - val find_exn : 'a. 'a t -> f:('a -> bool) -> 'a |
265 | | - |
266 | | - [@@@kind.default k2 = (value, float64, bits32, bits64, word, immediate, immediate64)] |
267 | | - |
268 | | - (** Returns the first evaluation of [f] that returns [Some]. Raises [Stdlib.Not_found] |
269 | | - or [Not_found_s] if [f] always returns [None]. *) |
270 | | - val find_map_exn : 'a 'b. 'a t -> f:('a -> ('b Option.t[@kind k2])) -> 'b |
| 280 | + (** [for_all2_exn t1 t2 ~f] fails if [length t1 <> length t2]. *) |
| 281 | + val for_all2_exn : 'a 'b. 'a t -> 'b t -> f:('a -> 'b -> bool) -> bool |
271 | 282 |
|
272 | | - (** [find_mapi_exn] is like [find_map_exn] but passes the index as an argument. *) |
273 | | - val find_mapi_exn : 'a 'b. 'a t -> f:(int -> 'a -> ('b Option.t[@kind k2])) -> 'b] |
| 283 | + (** [exists2_exn t1 t2 ~f] fails if [length t1 <> length t2]. *) |
| 284 | + val exists2_exn : 'a 'b. 'a t -> 'b t -> f:('a -> 'b -> bool) -> bool]] |
274 | 285 |
|
275 | 286 | (** [findi_exn t f] returns the first index [i] of [t] for which [f i t.(i)] is true. |
276 | 287 | It raises [Stdlib.Not_found] or [Not_found_s] if there is no such element. *) |
|
0 commit comments