Base.ArrayMutable vector of elements with O(1) get and set operations.
include Sexpable.S1 with type 'a t := 'a tval t_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a tval sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.tval t_sexp_grammar : Sexp.Private.Raw_grammar.tinclude Binary_searchable.S1 with type 'a t := 'a tval binary_search : ?pos:int -> ?len:int -> 'a t -> compare:('a -> 'key -> int) ->
[ `Last_strictly_less_than | `Last_less_than_or_equal_to | `Last_equal_to | `First_equal_to | `First_greater_than_or_equal_to | `First_strictly_greater_than ] -> 'key -> int optionval binary_search_segmented : ?pos:int -> ?len:int ->
'a t -> segment_of:('a -> [ `Left | `Right ]) ->
[ `Last_on_left | `First_on_right ] -> int optioninclude Container.S1 with type 'a t := 'a tval mem : 'a t -> 'a -> equal:('a -> 'a -> bool) -> boolChecks whether the provided element is there, using equal.
val length : 'a t -> intval is_empty : 'a t -> boolval iter : 'a t -> f:('a -> unit) -> unitval fold : 'a t -> init:'accum -> f:('accum -> 'a -> 'accum) -> 'accumfold t ~init ~f returns f (... f (f (f init e1) e2) e3 ...) en, where e1..en are the elements of t
val fold_result : 'a t -> init:'accum -> f:('accum -> 'a -> ('accum, 'e) Result.t) ->
('accum, 'e) Result.tfold_result t ~init ~f is a short-circuiting version of fold that runs in the Result monad. If f returns an Error _, that value is returned without any additional invocations of f.
val fold_until : 'a t -> init:'accum -> f:('accum -> 'a -> ('accum, 'final) Base__Container_intf.Export.Continue_or_stop.t) ->
finish:('accum -> 'final) -> 'finalfold_until t ~init ~f ~finish is a short-circuiting version of fold. If f returns Stop _ the computation ceases and results in that value. If f returns Continue _, the fold will proceed. If f never returns Stop _, the final result is computed by finish.
Example:
type maybe_negative =
| Found_negative of int
| All_nonnegative of { sum : int }
(** [first_neg_or_sum list] returns the first negative number in [list], if any,
otherwise returns the sum of the list. *)
let first_neg_or_sum =
List.fold_until ~init:0
~f:(fun sum x ->
if x < 0
then Stop (Found_negative x)
else Continue (sum + x))
~finish:(fun sum -> All_nonnegative { sum })
;;
let x = first_neg_or_sum [1; 2; 3; 4; 5]
val x : maybe_negative = All_nonnegative {sum = 15}
let y = first_neg_or_sum [1; 2; -3; 4; 5]
val y : maybe_negative = Found_negative -3val exists : 'a t -> f:('a -> bool) -> boolReturns true if and only if there exists an element for which the provided function evaluates to true. This is a short-circuiting operation.
val for_all : 'a t -> f:('a -> bool) -> boolReturns true if and only if the provided function evaluates to true for all elements. This is a short-circuiting operation.
val count : 'a t -> f:('a -> bool) -> intReturns the number of elements for which the provided function evaluates to true.
val sum : (module Base__Container_intf.Summable with type t = 'sum) -> 'a t -> f:('a -> 'sum) -> 'sumReturns the sum of f i for all i in the container.
val find : 'a t -> f:('a -> bool) -> 'a optionReturns as an option the first element for which f evaluates to true.
val find_map : 'a t -> f:('a -> 'b option) -> 'b optionReturns the first evaluation of f that returns Some, and returns None if there is no such element.
val to_list : 'a t -> 'a listval to_array : 'a t -> 'a arrayval min_elt : 'a t -> compare:('a -> 'a -> int) -> 'a optionReturns a minimum (resp maximum) element from the collection using the provided compare function, or None if the collection is empty. In case of a tie, the first element encountered while traversing the collection is returned. The implementation uses fold so it has the same complexity as fold.
val max_elt : 'a t -> compare:('a -> 'a -> int) -> 'a optioninclude Invariant.S1 with type 'a t := 'a tval invariant : ('a -> unit) -> 'a t -> unitMaximum length of a normal array. The maximum length of a float array is max_length/2 on 32-bit machines and max_length on 64-bit machines.
val get : 'a t -> int -> 'aArray.get a n returns the element number n of array a. The first element has number 0. The last element has number Array.length a - 1. You can also write a.(n) instead of Array.get a n.
Raise Invalid_argument "index out of bounds" if n is outside the range 0 to (Array.length a - 1).
val set : 'a t -> int -> 'a -> unitArray.set a n x modifies array a in place, replacing element number n with x. You can also write a.(n) <- x instead of Array.set a n x.
Raise Invalid_argument "index out of bounds" if n is outside the range 0 to Array.length a - 1.
val unsafe_get : 'a t -> int -> 'aUnsafe version of get. Can cause arbitrary behavior when used for an out-of-bounds array access.
val unsafe_set : 'a t -> int -> 'a -> unitUnsafe version of set. Can cause arbitrary behavior when used for an out-of-bounds array access.
val create : len:int -> 'a -> 'a tcreate ~len x creates an array of length len with the value x populated in each element.
val init : int -> f:(int -> 'a) -> 'a tinit n ~f creates an array of length n where the ith element (starting at zero) is initialized with f i.
Array.make_matrix dimx dimy e returns a two-dimensional array (an array of arrays) with first dimension dimx and second dimension dimy. All the elements of this new matrix are initially physically equal to e. The element (x,y) of a matrix m is accessed with the notation m.(x).(y).
Raise Invalid_argument if dimx or dimy is negative or greater than Array.max_length.
If the value of e is a floating-point number, then the maximum size is only Array.max_length / 2.
Array.append v1 v2 returns a fresh array containing the concatenation of the arrays v1 and v2.
Array.copy a returns a copy of a, that is, a fresh array containing the same elements as a.
val fill : 'a t -> pos:int -> len:int -> 'a -> unitArray.fill a ofs len x modifies the array a in place, storing x in elements number ofs to ofs + len - 1.
Raise Invalid_argument "Array.fill" if ofs and len do not designate a valid subarray of a.
Array.blit v1 o1 v2 o2 len copies len elements from array v1, starting at element number o1, to array v2, starting at element number o2. It works correctly even if v1 and v2 are the same array, and the source and destination chunks overlap.
Raise Invalid_argument "Array.blit" if o1 and len do not designate a valid subarray of v1, or if o2 and len do not designate a valid subarray of v2.
int_blit and float_blit provide fast bound-checked blits for immediate data types. The unsafe versions do not bound-check the arguments.
val of_list : 'a list -> 'a tArray.of_list l returns a fresh array containing the elements of l.
Array.map t ~f applies function f to all the elements of t, and builds an array with the results returned by f: [| f t.(0); f t.(1); ...; f t.(Array.length t - 1)
|].
folding_map is a version of map that threads an accumulator through calls to f.
Array.fold_map is a combination of Array.fold and Array.map that threads an accumulator through calls to f.
val iteri : 'a t -> f:(int -> 'a -> unit) -> unitLike Array.iter, but the function is applied to the index of the element as first argument, and the element itself as second argument.
Like Array.map, but the function is applied to the index of the element as first argument, and the element itself as second argument.
val foldi : 'a t -> init:'b -> f:(int -> 'b -> 'a -> 'b) -> 'bval fold_right : 'a t -> f:('a -> 'b -> 'b) -> init:'b -> 'bArray.fold_right f a ~init computes f a.(0) (f a.(1) ( ... (f a.(n-1) init) ...)), where n is the length of the array a.
All sort functions in this module sort in increasing order by default.
val sort : ?pos:int -> ?len:int -> 'a t -> compare:('a -> 'a -> int) -> unitsort uses constant heap space. stable_sort uses linear heap space.
To sort only part of the array, specify pos to be the index to start sorting from and len indicating how many elements to sort.
val stable_sort : 'a t -> compare:('a -> 'a -> int) -> unitval is_sorted : 'a t -> compare:('a -> 'a -> int) -> boolval is_sorted_strictly : 'a t -> compare:('a -> 'a -> int) -> boolis_sorted_strictly xs ~compare iff is_sorted xs ~compare and no two consecutive elements in xs are equal according to compare.
val concat_map : 'a t -> f:('a -> 'b array) -> 'b arrayLike List.concat_map, List.concat_mapi.
val concat_mapi : 'a t -> f:(int -> 'a -> 'b array) -> 'b arraytranspose in the sense of a matrix transpose. It returns None if the arrays are not all the same length.
filter_opt array returns a new array where None entries are omitted and Some x entries are replaced with x. Note that this changes the index at which elements will appear.
filter_map ~f array maps f over array and filters None out of the results.
Like filter_map but uses Array.mapi.
val for_alli : 'a t -> f:(int -> 'a -> bool) -> boolLike for_all, but passes the index as an argument.
val existsi : 'a t -> f:(int -> 'a -> bool) -> boolLike exists, but passes the index as an argument.
val counti : 'a t -> f:(int -> 'a -> bool) -> intLike count, but passes the index as an argument.
Functions with the 2 suffix raise an exception if the lengths of the two given arrays aren't the same.
for_all2_exn t1 t2 ~f fails if length t1 <> length t2.
exists2_exn t1 t2 ~f fails if length t1 <> length t2.
filter t ~f removes the elements for which f returns false.
val swap : 'a t -> int -> int -> unitswap arr i j swaps the value at index i with that at index j.
val rev_inplace : 'a t -> unitrev_inplace t reverses t in place.
val of_list_rev : 'a list -> 'a tof_list_rev l converts from list then reverses in place.
val of_list_map : 'a list -> f:('a -> 'b) -> 'b tof_list_map l ~f is the same as of_list (List.map l ~f).
val of_list_mapi : 'a list -> f:(int -> 'a -> 'b) -> 'b tof_list_mapi l ~f is the same as of_list (List.mapi l ~f).
val of_list_rev_map : 'a list -> f:('a -> 'b) -> 'b tof_list_rev_map l ~f is the same as of_list (List.rev_map l ~f).
val of_list_rev_mapi : 'a list -> f:(int -> 'a -> 'b) -> 'b tof_list_rev_mapi l ~f is the same as of_list (List.rev_mapi l ~f).
val map_inplace : 'a t -> f:('a -> 'a) -> unitModifies an array in place, applying f to every element of the array
val find_exn : 'a t -> f:('a -> bool) -> 'afind_exn f t returns the first a in t for which f t.(i) is true. It raises Caml.Not_found or Not_found_s if there is no such a.
val find_map_exn : 'a t -> f:('a -> 'b option) -> 'bReturns the first evaluation of f that returns Some. Raises Caml.Not_found or Not_found_s if f always returns None.
val findi : 'a t -> f:(int -> 'a -> bool) -> (int * 'a) optionfindi t f returns the first index i of t for which f i t.(i) is true
val findi_exn : 'a t -> f:(int -> 'a -> bool) -> int * 'afindi_exn t f returns the first index i of t for which f i t.(i) is true. It raises Caml.Not_found or Not_found_s if there is no such element.
val find_mapi : 'a t -> f:(int -> 'a -> 'b option) -> 'b optionfind_mapi t f is like find_map but passes the index as an argument.
val find_mapi_exn : 'a t -> f:(int -> 'a -> 'b option) -> 'bfind_mapi_exn is like find_map_exn but passes the index as an argument.
val find_consecutive_duplicate : 'a t -> equal:('a -> 'a -> bool) -> ('a * 'a) optionfind_consecutive_duplicate t ~equal returns the first pair of consecutive elements (a1, a2) in t such that equal a1 a2. They are returned in the same order as they appear in t.
val reduce : 'a t -> f:('a -> 'a -> 'a) -> 'a optionreduce f [a1; ...; an] is Some (f (... (f (f a1 a2) a3) ...) an). Returns None on the empty array.
val reduce_exn : 'a t -> f:('a -> 'a -> 'a) -> 'aval permute : ?random_state:Random.State.t -> 'a t -> unitpermute ?random_state t randomly permutes t in place.
permute side-effects random_state by repeated calls to Random.State.int. If random_state is not supplied, permute uses Random.State.default.
val random_element : ?random_state:Random.State.t -> 'a t -> 'a optionrandom_element ?random_state t is None if t is empty, else it is Some x for some x chosen uniformly at random from t.
random_element side-effects random_state by calling Random.State.int. If random_state is not supplied, random_element uses Random.State.default.
val random_element_exn : ?random_state:Random.State.t -> 'a t -> 'asorted_copy ar compare returns a shallow copy of ar that is sorted. Similar to List.sort
val last : 'a t -> 'aval to_sequence : 'a t -> 'a Sequence.tThe input array is copied internally so that future modifications of it do not change the sequence.
val to_sequence_mutable : 'a t -> 'a Sequence.tThe input array is shared with the sequence and modifications of it will result in modification of the sequence.