Blame src/extArray.mli

rpm-build 0f2925
(*
rpm-build 0f2925
 * ExtArray - additional and modified functions for arrays.
rpm-build 0f2925
 * Copyright (C) 2005 Richard W.M. Jones (rich @ annexia.org)
rpm-build 0f2925
 *
rpm-build 0f2925
 * This library is free software; you can redistribute it and/or
rpm-build 0f2925
 * modify it under the terms of the GNU Lesser General Public
rpm-build 0f2925
 * License as published by the Free Software Foundation; either
rpm-build 0f2925
 * version 2.1 of the License, or (at your option) any later version,
rpm-build 0f2925
 * with the special exception on linking described in file LICENSE.
rpm-build 0f2925
 *
rpm-build 0f2925
 * This library is distributed in the hope that it will be useful,
rpm-build 0f2925
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0f2925
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0f2925
 * Lesser General Public License for more details.
rpm-build 0f2925
 *
rpm-build 0f2925
 * You should have received a copy of the GNU Lesser General Public
rpm-build 0f2925
 * License along with this library; if not, write to the Free Software
rpm-build 0f2925
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
rpm-build 0f2925
 *)
rpm-build 0f2925
rpm-build 0f2925
(** Additional and modified functions for arrays.
rpm-build 0f2925
rpm-build 0f2925
  The OCaml standard library provides a module of array functions.
rpm-build 0f2925
  This ExtArray module can be used to override the Array module or
rpm-build 0f2925
  as a standalone module. It provides some additional functions.
rpm-build 0f2925
*)
rpm-build 0f2925
rpm-build 0f2925
module Array :
rpm-build 0f2925
sig
rpm-build 0f2925
rpm-build 0f2925
  (** {6 New functions} *)
rpm-build 0f2925
  val rev : 'a array -> 'a array
rpm-build 0f2925
    (** Array reversal. *)
rpm-build 0f2925
rpm-build 0f2925
  val rev_in_place : 'a array -> unit
rpm-build 0f2925
    (** In-place array reversal.  The array argument is updated. *)
rpm-build 0f2925
rpm-build 0f2925
  val iter2 : ('a -> 'b -> unit) -> 'a array -> 'b array -> unit
rpm-build 0f2925
    (** [Array.iter2 f [|a1; ...; an|] [|b1; ...; bn|]] performs
rpm-build 0f2925
    calls [f a1 b1; ...; f an bn] in that order.
rpm-build 0f2925
rpm-build 0f2925
    @raise Invalid_argument if the length of [a1] does not equal the
rpm-build 0f2925
    length of [a2]. *)
rpm-build 0f2925
rpm-build 0f2925
  val map2 : ('a -> 'b -> 'c) -> 'a array -> 'b array -> 'c array
rpm-build 0f2925
    (** [Array.map2 f [|a1; ...; an|] [|b1; ...; bn|]] creates new array
rpm-build 0f2925
    [[|f a1 b1; ...; f an bn|]].
rpm-build 0f2925
rpm-build 0f2925
    @raise Invalid_argument if the length of [a1] does not equal the
rpm-build 0f2925
    length of [a2]. *)
rpm-build 0f2925
rpm-build 0f2925
  val for_all : ('a -> bool) -> 'a array -> bool
rpm-build 0f2925
    (** [for_all p [a1; ...; an]] checks if all elements of the array
rpm-build 0f2925
  satisfy the predicate [p].  That is, it returns
rpm-build 0f2925
  [ (p a1) && (p a2) && ... && (p an)].
rpm-build 0f2925
    *)
rpm-build 0f2925
rpm-build 0f2925
  val exists : ('a -> bool) -> 'a array -> bool
rpm-build 0f2925
    (** [exists p [a1; ...; an]] checks if at least one element of
rpm-build 0f2925
  the array satisfies the predicate [p].  That is, it returns
rpm-build 0f2925
  [ (p a1) || (p a2) || ... || (p an)].
rpm-build 0f2925
    *)
rpm-build 0f2925
rpm-build 0f2925
  val mem : 'a -> 'a array -> bool
rpm-build 0f2925
    (** [mem m a] is true if and only if [m] is equal to an element of [a]. *)
rpm-build 0f2925
rpm-build 0f2925
  val memq : 'a -> 'a array -> bool
rpm-build 0f2925
    (** Same as {!Array.mem} but uses physical equality instead of
rpm-build 0f2925
  structural equality to compare array elements.
rpm-build 0f2925
    *)
rpm-build 0f2925
rpm-build 0f2925
  val find : ('a -> bool) -> 'a array -> 'a
rpm-build 0f2925
    (** [find p a] returns the first element of array [a]
rpm-build 0f2925
  that satisfies the predicate [p].
rpm-build 0f2925
  Raise [Not_found] if there is no value that satisfies [p] in the
rpm-build 0f2925
  array [a].
rpm-build 0f2925
    *)
rpm-build 0f2925
rpm-build 0f2925
  val findi : ('a -> bool) -> 'a array -> int
rpm-build 0f2925
    (** [findi p a] returns the index of the first element of array [a]
rpm-build 0f2925
  that satisfies the predicate [p].
rpm-build 0f2925
  Raise [Not_found] if there is no value that satisfies [p] in the
rpm-build 0f2925
  array [a].
rpm-build 0f2925
    *)
rpm-build 0f2925
rpm-build 0f2925
  val filter : ('a -> bool) -> 'a array -> 'a array
rpm-build 0f2925
    (** [filter p a] returns all the elements of the array [a]
rpm-build 0f2925
  that satisfy the predicate [p].  The order of the elements
rpm-build 0f2925
  in the input array is preserved.  *)
rpm-build 0f2925
rpm-build 0f2925
  val find_all : ('a -> bool) -> 'a array -> 'a array
rpm-build 0f2925
    (** [find_all] is another name for {!Array.filter}. *)
rpm-build 0f2925
rpm-build 0f2925
  val partition : ('a -> bool) -> 'a array -> 'a array * 'a array
rpm-build 0f2925
    (** [partition p a] returns a pair of arrays [(a1, a2)], where
rpm-build 0f2925
  [a1] is the array of all the elements of [a] that
rpm-build 0f2925
  satisfy the predicate [p], and [a2] is the array of all the
rpm-build 0f2925
  elements of [a] that do not satisfy [p].
rpm-build 0f2925
  The order of the elements in the input array is preserved. *)
rpm-build 0f2925
rpm-build 0f2925
  (** {6 Enumerations} *)
rpm-build 0f2925
rpm-build 0f2925
  val enum : 'a array -> 'a Enum.t
rpm-build 0f2925
    (** Returns an enumeration of the elements of an array. *)
rpm-build 0f2925
rpm-build 0f2925
  val of_enum : 'a Enum.t -> 'a array
rpm-build 0f2925
    (** Build an array from an enumeration. *)
rpm-build 0f2925
rpm-build 0f2925
  (** {6 Compatibility functions} *)
rpm-build 0f2925
rpm-build 0f2925
  (** These functions are reimplemented in extlib when they are missing from the stdlib *)
rpm-build 0f2925
rpm-build 0f2925
#if OCAML >= 403
rpm-build 0f2925
  external create_float : int -> float array = "caml_make_float_vect"
rpm-build 0f2925
#else
rpm-build 0f2925
  val create_float : int -> float array
rpm-build 0f2925
#endif
rpm-build 0f2925
rpm-build 0f2925
  val make_float : int -> float array
rpm-build 0f2925
rpm-build 0f2925
#if OCAML >= 406
rpm-build 0f2925
  module Floatarray :
rpm-build 0f2925
  sig
rpm-build 0f2925
    external create : int -> floatarray = "caml_floatarray_create"
rpm-build 0f2925
    external length : floatarray -> int = "%floatarray_length"
rpm-build 0f2925
    external get : floatarray -> int -> float = "%floatarray_safe_get"
rpm-build 0f2925
    external set : floatarray -> int -> float -> unit = "%floatarray_safe_set"
rpm-build 0f2925
    external unsafe_get : floatarray -> int -> float = "%floatarray_unsafe_get"
rpm-build 0f2925
    external unsafe_set : floatarray -> int -> float -> unit = "%floatarray_unsafe_set"
rpm-build 0f2925
  end
rpm-build 0f2925
#endif
rpm-build 0f2925
rpm-build 0f2925
  (** {6 Old functions} *)
rpm-build 0f2925
rpm-build 0f2925
  (** These functions are already part of the Ocaml standard library
rpm-build 0f2925
      and have not been modified. Please refer to the Ocaml Manual for
rpm-build 0f2925
      documentation. *)
rpm-build 0f2925
rpm-build 0f2925
  external length : 'a array -> int = "%array_length"
rpm-build 0f2925
  external get : 'a array -> int -> 'a = "%array_safe_get"
rpm-build 0f2925
  external set : 'a array -> int -> 'a -> unit = "%array_safe_set"
rpm-build 0f2925
  external make : int -> 'a -> 'a array = "caml_make_vect"
rpm-build 0f2925
  external create : int -> 'a -> 'a array = "caml_make_vect"
rpm-build 0f2925
  val init : int -> (int -> 'a) -> 'a array
rpm-build 0f2925
  val make_matrix : int -> int -> 'a -> 'a array array
rpm-build 0f2925
  val create_matrix : int -> int -> 'a -> 'a array array
rpm-build 0f2925
  val append : 'a array -> 'a array -> 'a array
rpm-build 0f2925
  val concat : 'a array list -> 'a array
rpm-build 0f2925
  val sub : 'a array -> int -> int -> 'a array
rpm-build 0f2925
  val copy : 'a array -> 'a array
rpm-build 0f2925
  val fill : 'a array -> int -> int -> 'a -> unit
rpm-build 0f2925
  val blit : 'a array -> int -> 'a array -> int -> int -> unit
rpm-build 0f2925
  val to_list : 'a array -> 'a list
rpm-build 0f2925
  val of_list : 'a list -> 'a array
rpm-build 0f2925
  val iter : ('a -> unit) -> 'a array -> unit
rpm-build 0f2925
  val map : ('a -> 'b) -> 'a array -> 'b array
rpm-build 0f2925
  val iteri : (int -> 'a -> unit) -> 'a array -> unit
rpm-build 0f2925
  val mapi : (int -> 'a -> 'b) -> 'a array -> 'b array
rpm-build 0f2925
  val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b array -> 'a
rpm-build 0f2925
  val fold_right : ('b -> 'a -> 'a) -> 'b array -> 'a -> 'a
rpm-build 0f2925
  val sort : ('a -> 'a -> int) -> 'a array -> unit
rpm-build 0f2925
  val stable_sort : ('a -> 'a -> int) -> 'a array -> unit
rpm-build 0f2925
  val fast_sort : ('a -> 'a -> int) -> 'a array -> unit
rpm-build 0f2925
  external unsafe_get : 'a array -> int -> 'a = "%array_unsafe_get"
rpm-build 0f2925
  external unsafe_set : 'a array -> int -> 'a -> unit = "%array_unsafe_set"
rpm-build 0f2925
rpm-build 0f2925
#if OCAML >= 407
rpm-build 0f2925
  (** [*_seq] functions were introduced in OCaml 4.07.0, and are _not_ implemented in extlib for older OCaml versions *)
rpm-build 0f2925
  val to_seq : 'a array -> 'a Seq.t
rpm-build 0f2925
  val to_seqi : 'a array -> (int * 'a) Seq.t
rpm-build 0f2925
  val of_seq : 'a Seq.t -> 'a array
rpm-build 0f2925
#endif
rpm-build 0f2925
rpm-build 0f2925
end