Module Ppx_hardcaml_runtime0.Iarray

include module type of struct include Core.Iarray end
type 'a t = 'a Base.Iarray.t
include sig ... end
include Bin_prot.Binable.S1__local with type 'a t := 'a Base.Iarray.t
val bin_shape_t : Bin_prot.Shape.t -> Bin_prot.Shape.t
include sig ... end
val bin_size_t : 'a. ('a, 'a Base.Iarray.t) Bin_prot.Size.sizer1
val bin_write_t : 'a. ('a, 'a Base.Iarray.t) Bin_prot.Write.writer1
val bin_read_t : 'a. ('a, 'a Base.Iarray.t) Bin_prot.Read.reader1
val __bin_read_t__ : 'a. ('a, 'a Base.Iarray.t) Bin_prot.Read.vtag_reader1
val bin_writer_t : 'a. ('a, 'a Base.Iarray.t) Bin_prot.Type_class.S1.writer
val bin_reader_t : 'a. ('a, 'a Base.Iarray.t) Bin_prot.Type_class.S1.reader
val bin_t : 'a. ('a, 'a Base.Iarray.t) Bin_prot.Type_class.S1.t
val quickcheck_generator__portable : 'a. 'a Ppx_quickcheck_runtime.Base_quickcheck.Generator.t @ portable -> 'a Base.Iarray.t Ppx_quickcheck_runtime.Base_quickcheck.Generator.t @ portable @@ portable
val quickcheck_observer__portable : 'a. 'a Ppx_quickcheck_runtime.Base_quickcheck.Observer.t @ portable -> 'a Base.Iarray.t Ppx_quickcheck_runtime.Base_quickcheck.Observer.t @ portable @@ portable
val quickcheck_shrinker__portable : 'a. 'a Ppx_quickcheck_runtime.Base_quickcheck.Shrinker.t @ portable -> 'a Base.Iarray.t Ppx_quickcheck_runtime.Base_quickcheck.Shrinker.t @ portable @@ portable
include sig ... end
val compare : 'a. ('a -> 'a -> int) -> 'a t -> 'a t -> int
val compare__local : 'a. ('a @ local -> ('a @ local -> int) @ local) -> 'a t @ local -> ('a t @ local -> int) @ local
val equal : 'a. ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
val equal__local : 'a. ('a @ local -> ('a @ local -> bool) @ local) -> 'a t @ local -> ('a t @ local -> bool) @ local
val sexp_of_t : 'a. ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
val sexp_of_t__stack : 'a. ('a @ local -> Sexplib0.Sexp.t @ local) -> 'a t @ local -> Sexplib0.Sexp.t @ local
val t_of_sexp : 'a. (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a t
val t_sexp_grammar : 'a. 'a Sexplib0.Sexp_grammar.t -> 'a t Sexplib0.Sexp_grammar.t @@ portable
include sig ... end
val globalize : 'a. ('a @ local -> 'a) -> 'a t @ local -> 'a t
include Ppx_hash_lib.Hashable.S1_any with type 'a t := 'a t

Standard interfaces

include Base.Binary_searchable.S1__local with type 'a t := 'a t

See Binary_search.binary_search in binary_search.ml

See Binary_search.binary_search_segmented in binary_search.ml

val binary_search_segmented : ?pos:int -> ?len:int -> 'a t -> segment_of:('a -> [ `Left | `Right ]) @ local -> ([ `Last_on_left | `First_on_right ] -> int option @ local) @ local
include Base.Indexed_container.S1_with_creators__stack with type 'a t := 'a t
include Base.Container.S1__''value''__stack with type 'a t := 'a t
include sig ... end
include Base.Container.Generic_types__''value'' with type ('a, _, _) t := 'a t with type 'a elt := 'a

These are all like their equivalents in Container except that an index starting at 0 is added as the first argument to f.

val iteri : 'a 'p1 'p2. 'a t -> f:(int -> ('a -> unit) @ local) @ local -> unit
val existsi : 'a 'p1 'p2. 'a t -> f:(int -> ('a -> bool) @ local) @ local -> bool
val for_alli : 'a 'p1 'p2. 'a t -> f:(int -> ('a -> bool) @ local) @ local -> bool
val counti : 'a 'p1 'p2. 'a t -> f:(int -> ('a -> bool) @ local) @ local -> int
val iteri_until : 'a 'p1 'p2 'final. 'a t -> f: (int -> ('a -> (unit, 'final) Base.Container.Continue_or_stop.t) @ local) @ local -> (finish:(int -> 'final) @ local -> 'final) @ local
val find_mapi : 'a 'p1 'p2 'b. 'a t -> f:(int -> ('a -> 'b option) @ local) @ local -> 'b option
val foldi_until : 'a 'p1 'p2 'acc 'final. 'a t -> init:'acc -> f: (int -> ('acc -> ('a -> ('acc, 'final) Base.Container.Continue_or_stop.t) @ local) @ local) @ local -> (finish:(int -> ('acc -> 'final) @ local) @ local -> 'final) @ local
val findi : 'a 'p1 'p2. 'a t -> f:(int -> ('a -> bool) @ local) @ local -> (int * 'a) option
include Base.Container.S1_with_creators__''value''__stack with type 'a t := 'a t
include sig ... end
val is_empty : 'a 'p1 'p2. 'a t @ local -> bool
val iter : 'a 'p1 'p2. 'a t -> f:('a -> unit) @ local -> unit

iter must allow exceptions raised in f to escape, terminating the iteration cleanly. The same holds for all functions below taking an f.

val exists : 'a 'p1 'p2. 'a t -> f:('a -> bool) @ local -> bool

Returns 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 'p1 'p2. 'a t -> f:('a -> bool) @ local -> bool

Returns true if and only if the provided function evaluates to true for all elements. This is a short-circuiting operation.

val count : 'a 'p1 'p2. 'a t -> f:('a -> bool) @ local -> int

Returns the number of elements for which the provided function evaluates to true.

val find : 'a 'p1 'p2. 'a t -> f:('a -> bool) @ local -> 'a Option.t

Returns as an option the first element for which f evaluates to true.

val to_list : 'a 'p1 'p2. 'a t -> 'a list
val min_elt : 'a 'p1 'p2. 'a t -> compare:('a -> ('a -> int) @ local) @ local -> 'a Option.t

Returns a min (resp. max) element from the collection using the provided compare function. 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. Returns None iff the collection is empty.

val max_elt : 'a 'p1 'p2. 'a t -> compare:('a -> ('a -> int) @ local) @ local -> 'a Option.t
val sum : 'a 'sum 'p1 'p2. (module Base.Container.Summable with type t = 'sum) -> 'a t -> f:('a -> 'sum) @ local -> 'sum

Returns the sum of f i for all i in the container. The order in which the elements will be summed is unspecified.

val iter_until : 'a 'p1 'p2 'final. 'a t -> f:('a -> (unit, 'final) Base.Container.Continue_or_stop.t) @ local -> (finish:(unit -> 'final) @ local -> 'final) @ local

iter_until t ~f ~finish is a short-circuiting version of iter. If f returns Stop x the computation ceases and returns x. If f always returns Continue () the final result is computed by finish.

val fold_result : 'a 'p1 'p2 'acc 'e. 'a t -> init:'acc -> f:('acc -> ('a -> ('acc, 'e) Result.t) @ local) @ local -> ('acc, 'e) Result.t

fold_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 find_map : 'a 'p1 'p2 'b. 'a t -> f:('a -> 'b Option.t) @ local -> 'b Option.t

Returns the first evaluation of f that returns Some, and returns None if there is no such element.

val fold_until : 'a 'p1 'p2 'acc 'final. 'a t -> init:'acc -> f: ('acc -> ('a -> ('acc, 'final) Base.Container.Continue_or_stop.t) @ local) @ local -> (finish:('acc -> 'final) @ local -> 'final) @ local

fold_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 -3
val mem : 'a 'p1 'p2. 'a t -> 'a -> equal:('a -> ('a -> bool) @ local) @ local -> bool

Checks whether the provided element is there, using equal.

include sig ... end
val of_list : 'a 'p1 'p2. 'a list -> 'a t
val append : 'a 'p1 'p2. 'a t -> 'a t -> 'a t

E.g., append (of_list [a; b]) (of_list [c; d; e]) is of_list [a; b; c; d; e]

val concat : 'a 'p1 'p2. 'a t t -> 'a t

Concatenates a nested container. The elements of the inner containers are concatenated together in order to give the result.

val filter : 'a 'p1 'p2. 'a t -> f:('a -> bool) @ local -> 'a t

filter t ~f returns all the elements of t that satisfy the predicate f.

val partition_tf : 'a 'p1 'p2. 'a t -> f:('a -> bool) @ local -> 'a t * 'a t

partition_tf t ~f returns a pair t1, t2, where t1 is all elements of t that satisfy f, and t2 is all elements of t that do not satisfy f. The "tf" suffix is mnemonic to remind readers that the result is (trues, falses).

val map : 'a 'p1 'p2 'b. 'a t -> f:('a -> 'b) @ local -> 'b t

map f (of_list [a1; ...; an]) applies f to a1, a2, ..., an, in order, and builds a result equivalent to of_list [f a1; ...; f an].

val filter_map : 'a 'p1 'p2 'b. 'a t -> f:('a -> 'b Option.t) @ local -> 'b t

filter_map t ~f applies f to every x in t. The result contains every y for which f x returns Some y.

val concat_map : 'a 'p1 'p2 'b. 'a t -> f:('a -> 'b t) @ local -> 'b t

concat_map t ~f is equivalent to concat (map t ~f).

val partition_map : 'a 'p1 'p2 'b 'c. 'a t -> f:('a -> ('b, 'c) Either.t) @ local -> 'b t * 'c t

partition_map t ~f partitions t according to f.

val to_array : 'a. 'a t -> 'a array
val of_array : 'a. 'a array -> 'a t
include Base.Container.Generic_types__''value'' with type ('a, _, _) t := 'a t with type 'a elt := 'a
val filteri : 'a 'p1 'p2. 'a t -> f:(int -> ('a -> bool) @ local) @ local -> 'a t
val partitioni_tf : 'a 'p1 'p2. 'a t -> f:(int -> ('a -> bool) @ local) @ local -> 'a t * 'a t

partitioni_tf t ~f is like partition_tf. Additionally, it passes the index as an argument.

val mapi : 'a 'p1 'p2 'b. 'a t -> f:(int -> ('a -> 'b) @ local) @ local -> 'b t

mapi is like map. Additionally, it passes in the index of each element as the first argument to the mapped function.

val filter_mapi : 'a 'p1 'p2 'b. 'a t -> f:(int -> ('a -> 'b option) @ local) @ local -> 'b t

filter_mapi is like filter_map. Additionally, it passes in the index of each element as the first argument to the mapped function.

val concat_mapi : 'a 'p1 'p2 'b. 'a t -> f:(int -> ('a -> 'b t) @ local) @ local -> 'b t

concat_mapi t ~f is like concat_map. Additionally, it passes the index as an argument.

val partition_mapi : 'a 'p1 'p2 'b 'c. 'a t -> f:(int -> ('a -> ('b, 'c) Base__.Either0.t) @ local) @ local -> 'b t * 'c t

partition_mapi t ~f is like partition_map. Additionally, it passes the index as an argument.

include Base.Invariant.S1 with type 'a t := 'a t
val invariant : ('a -> unit) -> 'a t -> unit

Operators

module O = Core.Iarray.O
val (.:()) : 'a. 'a Basement.Stdlib_iarray_labels.t -> int -> 'a

An alias for get.

Indexing

val length : 'a. 'a t @ immutable -> int
val get : 'a. 'a t -> int -> 'a
val get_opt : 'a t -> int -> 'a option
val unsafe_get : 'a. 'a t -> int -> 'a
val last_exn : 'a t -> 'a

Functional update

val set : 'a t -> int -> 'a -> 'a t
val update : 'a t -> int -> f:('a -> 'a) -> 'a t

Constructors

val empty : _ t
val singleton : 'a -> 'a t
val create : len:int -> 'a -> mutate:('a array @ local -> unit) @ local -> 'a Basement.Stdlib_iarray_labels.t
val init : 'a. int -> f:(int -> 'a) @ local -> 'a t

Conversions

val of_sequence : 'a Base.Sequence.t -> 'a t
val to_sequence : 'a t -> 'a Base.Sequence.t
val of_list_rev : 'a list -> 'a t
val of_list_map : 'a list -> f:('a -> 'b) @ local -> 'b t
val of_list_mapi : 'a list -> f:(int -> ('a -> 'b) @ local) @ local -> 'b t
val of_list_rev_map : 'a list -> f:('a -> 'b) @ local -> 'b t

Subsequences

val prefix : 'a t -> len:int -> 'a t
val suffix : 'a t -> len:int -> 'a t
val drop_prefix : 'a t -> len:int -> 'a t
val drop_suffix : 'a t -> len:int -> 'a t
val group : 'a t -> break:('a -> ('a -> bool) @ local) @ local -> 'a t t
val split_n : 'a t -> int -> 'a t * 'a t

split_n t n returns a pair of iarrays (first, second) where first contains the first n elements of t and second contains the remaining elements.

  • If n >= length t, returns (t, empty).
  • If n <= 0, returns (empty, t).
val chunks_of : 'a t -> length:int -> 'a t t

chunks_of t ~length returns an iarray of iarrays whose concatenation is equal to the original iarray. Every iarray has length elements, except for possibly the last iarray, which may have fewer. chunks_of raises if length <= 0.

Reordering

val rev : 'a t -> 'a t
val sort : 'a t -> compare:('a -> ('a -> int) @ local) @ local -> 'a t
val stable_sort : 'a t -> compare:('a -> 'a -> int) -> 'a t
val dedup_and_sort : 'a t -> compare:('a -> ('a -> int) @ local) @ local -> 'a t
val sort_and_group : 'a t -> compare:('a -> ('a -> int) @ local) @ local -> 'a t t
val is_sorted : 'a t -> compare:('a -> ('a -> int) @ local) @ local -> bool
val is_sorted_strictly : 'a t -> compare:('a -> ('a -> int) @ local) @ local -> bool

Combining elements

val reduce : 'a t -> f:('a -> ('a -> 'a) @ local) @ local -> 'a option
val reduce_exn : 'a t -> f:('a -> ('a -> 'a) @ local) @ local -> 'a
val combine_errors : 'a Base.Or_error.t t -> 'a t Base.Or_error.t
val combine_errors_unit : unit Base.Or_error.t t -> unit Base.Or_error.t
val fold : 'a 'acc. 'a t -> init:'acc -> f:('acc -> ('a -> 'acc) @ local) @ local -> 'acc
val foldi : 'a 'acc. 'a t -> init:'acc -> f:(int -> ('acc -> ('a -> 'acc) @ local) @ local) @ local -> 'acc
val fold_right : 'a 'acc. 'a t -> init:'acc -> f:('a -> ('acc -> 'acc) @ local) @ local -> 'acc
val fold_map : 'a t -> init:'acc -> f:('acc -> ('a -> 'acc * 'b) @ local) @ local -> 'acc * 'b t
val fold_mapi : 'a t -> init:'acc -> f:(int -> ('acc -> ('a -> 'acc * 'b) @ local) @ local) @ local -> 'acc * 'b t

Multiple arrays

val zip : 'a t -> 'b t -> ('a * 'b) t option
val zip_exn : 'a t -> 'b t -> ('a * 'b) t
val unzip : ('a * 'b) t -> 'a t * 'b t
val map2_exn : 'a t -> 'b t -> f:('a -> ('b -> 'c) @ local) @ local -> 'c t
val iter2_exn : 'a t -> 'b t -> f:('a -> ('b -> unit) @ local) @ local -> unit
val cartesian_product : 'a t -> 'b t -> ('a * 'b) t

Random elements

val random_element : ?random_state:Base.Random.State.t -> 'a t -> 'a option
val random_element_exn : ?random_state:Base.Random.State.t -> 'a t -> 'a

Blit operations

val sub : 'a t -> pos:int -> len:int -> 'a t
val subo : ?pos:int -> ?len:int -> 'a t -> 'a t
module Of_array = Core.Iarray.Of_array
module To_array = Core.Iarray.To_array
module Local = Core.Iarray.Local

Operations for local iarrays.

module Unique = Core.Iarray.Unique

Operations for unique iarrays

Unsafe conversions

Immutable arrays can be converted to and from mutable arrays, as they can have the same representation. One must be careful not to modify the mutable array sharing a representation with an immutable array at any time when both are reachable. Doing so violates the invariants of the immutable array. The OCaml compiler might rely on these invariants when compiling or optimizing code that uses immutable arrays.

val unsafe_to_array__promise_no_mutation : 'a. 'a t -> 'a array
val unsafe_of_array__promise_no_mutation : 'a. 'a array -> 'a t
module Stable = Core.Iarray.Stable
val for_ : int -> f:(int -> unit) -> unit