|
| 1 | +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. |
| 2 | + * |
| 3 | + * This program is free software: you can redistribute it and/or modify |
| 4 | + * it under the terms of the GNU Lesser General Public License as published by |
| 5 | + * the Free Software Foundation, either version 3 of the License, or |
| 6 | + * (at your option) any later version. |
| 7 | + * |
| 8 | + * In addition to the permissions granted to you by the LGPL, you may combine |
| 9 | + * or link a "work that uses the Library" with a publicly distributed version |
| 10 | + * of this file to produce a combined library or application, then distribute |
| 11 | + * that combined work under the terms of your choosing, with no requirement |
| 12 | + * to comply with the obligations normally placed on you by section 4 of the |
| 13 | + * LGPL version 3 (or the corresponding section of a later version of the LGPL |
| 14 | + * should you choose to use a later version). |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU Lesser General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Lesser General Public License |
| 22 | + * along with this program; if not, write to the Free Software |
| 23 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) |
| 24 | + |
| 25 | +type 'a t = 'a array |
| 26 | + |
| 27 | +val filterInPlace : ('a -> bool [@bs]) -> 'a t -> unit |
| 28 | + |
| 29 | +val empty : 'a t -> unit |
| 30 | + |
| 31 | +val pushBack : 'a -> 'a t -> unit |
| 32 | + |
| 33 | +val copy : 'a t -> 'a t |
| 34 | +(** shallow copy *) |
| 35 | + |
| 36 | +val memByRef : 'a -> 'a t -> bool |
| 37 | + |
| 38 | +val iter : ('a -> unit [@bs]) -> 'a t -> unit |
| 39 | +val iteri : (int -> 'a -> unit [@bs]) -> 'a t -> unit |
| 40 | +val ofList : 'a Bs_list.t -> 'a t |
| 41 | +val toList : 'a t -> 'a Bs_list.t |
| 42 | + |
| 43 | +val map : ('a -> 'b [@bs]) -> 'a t -> 'b t |
| 44 | +val mapi : (int -> 'a -> 'b [@bs]) -> 'a t -> 'b t |
| 45 | +val foldLeft : ('a -> 'b -> 'a [@bs]) -> 'a -> 'b t -> 'a |
| 46 | +val foldRight : ('b -> 'a -> 'a [@bs]) -> 'b t -> 'a -> 'a |
| 47 | +external length : 'a t -> int = "%array_length" |
| 48 | +(** Return the length (number of elements) of the given array. *) |
| 49 | + |
| 50 | +external get : 'a t -> int -> 'a = "%array_safe_get" |
| 51 | +(** [Array.get a n] returns the element number [n] of array [a]. |
| 52 | + The first element has number 0. |
| 53 | + The last element has number [Array.length a - 1]. |
| 54 | + You can also write [a.(n)] instead of [Array.get a n]. |
| 55 | +
|
| 56 | + Raise [Invalid_argument "index out of bounds"] |
| 57 | + if [n] is outside the range 0 to [(Array.length a - 1)]. *) |
| 58 | + |
| 59 | +external set : 'a t -> int -> 'a -> unit = "%array_safe_set" |
| 60 | +(** [Array.set a n x] modifies array [a] in place, replacing |
| 61 | + element number [n] with [x]. |
| 62 | + You can also write [a.(n) <- x] instead of [Array.set a n x]. |
| 63 | +
|
| 64 | + Raise [Invalid_argument "index out of bounds"] |
| 65 | + if [n] is outside the range 0 to [Array.length a - 1]. *) |
| 66 | + |
| 67 | + |
| 68 | +external make : int -> 'a -> 'a t = "caml_make_vect" |
| 69 | +(** [Array.make n x] returns a fresh array of length [n], |
| 70 | + initialized with [x]. |
| 71 | + All the elements of this new array are initially |
| 72 | + physically equal to [x] (in the sense of the [==] predicate). |
| 73 | + Consequently, if [x] is mutable, it is shared among all elements |
| 74 | + of the array, and modifying [x] through one of the array entries |
| 75 | + will modify all other entries at the same time. |
| 76 | +
|
| 77 | + Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. |
| 78 | + If the value of [x] is a floating-point number, then the maximum |
| 79 | + size is only [Sys.max_array_length / 2].*) |
| 80 | + |
| 81 | + |
| 82 | +val init : int -> (int -> 'a [@bs]) -> 'a t |
| 83 | +(** @raise RangeError *) |
| 84 | + |
| 85 | +(*val append : 'a t -> 'a t -> 'a t *) |
| 86 | +(** create a new array, there is no shallow-sharing |
| 87 | + between the output and input |
| 88 | +*) |
| 89 | + |
| 90 | +external unsafe_get : 'a t -> int -> 'a = "%array_unsafe_get" |
| 91 | +external unsafe_set : 'a t -> int -> 'a -> unit = "%array_unsafe_set" |
| 92 | + |
| 93 | + |
0 commit comments