Core.Uniform_array
This module extends Base.Uniform_array
with bin_io.
type 'a t = 'a Base.Uniform_array.t
include Bin_prot.Binable.S1 with type 'a t := 'a t
val bin_shape_t : Bin_prot.Shape.t -> Bin_prot.Shape.t
val bin_size_t : ('a, 'a t) Bin_prot.Size.sizer1
val bin_write_t : ('a, 'a t) Bin_prot.Write.writer1
val bin_read_t : ('a, 'a t) Bin_prot.Read.reader1
val __bin_read_t__ : ('a, int -> 'a t) Bin_prot.Read.reader1
val bin_writer_t : ('a, 'a t) Bin_prot.Type_class.S1.writer
val bin_reader_t : ('a, 'a t) Bin_prot.Type_class.S1.reader
val bin_t : ('a, 'a t) Bin_prot.Type_class.S1.t
include Sexplib0.Sexpable.S1 with type 'a t := 'a t
include module type of struct include Base.Uniform_array end
with type 'a t := 'a t
include Sexplib0.Sexpable.S1 with type 'a t := 'a t
val t_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a t
val sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
val t_sexp_grammar : 'a Sexplib0.Sexp_grammar.t -> 'a t Sexplib0.Sexp_grammar.t
val invariant : _ t -> unit
val empty : _ t
val create : len:int -> 'a -> 'a t
val singleton : 'a -> 'a t
val init : int -> f:(int -> 'a) -> 'a t
val length : 'a t -> int
val get : 'a t -> int -> 'a
val unsafe_get : 'a t -> int -> 'a
val unsafe_get_local : 'a t -> int -> 'a
val set : 'a t -> int -> 'a -> unit
val unsafe_set : 'a t -> int -> 'a -> unit
val swap : _ t -> int -> int -> unit
val unsafe_set_omit_phys_equal_check : 'a t -> int -> 'a -> unit
unsafe_set_omit_phys_equal_check
is like unsafe_set
, except it doesn't do a phys_equal
check to try to skip caml_modify
. It is safe to call this even if the values are phys_equal
.
val unsafe_set_with_caml_modify : 'a t -> int -> 'a -> unit
unsafe_set_with_caml_modify
always calls caml_modify
before setting and never gets the old value. This is like unsafe_set_omit_phys_equal_check
except it doesn't check whether the old value and the value being set are integers to try to skip caml_modify
.
val set_with_caml_modify : 'a t -> int -> 'a -> unit
Same as unsafe_set_with_caml_modify
, but with bounds check.
val iter : 'a t -> f:('a -> unit) -> unit
val iteri : 'a t -> f:(int -> 'a -> unit) -> unit
Like iter
, but the function is applied to the index of the element as first argument, and the element itself as second argument.
val fold : 'a t -> init:'acc -> f:('acc -> 'a -> 'acc) -> 'acc
val foldi : 'a t -> init:'acc -> f:(int -> 'acc -> 'a -> 'acc) -> 'acc
val unsafe_to_array_inplace__promise_not_a_float : 'a t -> 'a array
unsafe_to_array_inplace__promise_not_a_float
converts from a t
to an array
in place. This function is unsafe if the underlying type is a float.
val of_array : 'a array -> 'a t
of_array
and to_array
return fresh arrays with the same contents rather than returning a reference to the underlying array.
val to_array : 'a t -> 'a array
val of_list : 'a list -> 'a t
val of_list_rev : 'a list -> 'a t
val to_list : 'a t -> 'a list
include Base.Blit.S1 with type 'a t := 'a t
val exists : 'a t -> f:('a -> bool) -> bool
val existsi : 'a t -> f:(int -> 'a -> bool) -> bool
val for_all : 'a t -> f:('a -> bool) -> bool
val for_alli : 'a t -> f:(int -> 'a -> bool) -> bool
val partition_map : 'a t -> f:('a -> ('b, 'c) Base.Either.t) -> 'b t * 'c t
val find : 'a t -> f:('a -> bool) -> 'a option
val findi : 'a t -> f:(int -> 'a -> bool) -> (int * 'a) option
val find_map : 'a t -> f:('a -> 'b option) -> 'b option
val find_mapi : 'a t -> f:(int -> 'a -> 'b option) -> 'b option
Functions with the 2 suffix raise an exception if the lengths of the two given arrays aren't the same.
val min_elt : 'a t -> compare:('a -> 'a -> int) -> 'a option
val max_elt : 'a t -> compare:('a -> 'a -> int) -> 'a option
val sort : ?pos:int -> ?len:int -> 'a t -> compare:('a -> 'a -> int) -> unit
sort
uses constant 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.
include Base.Binary_searchable.S1 with type 'a t := 'a t
val 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 option
val binary_search_segmented :
?pos:int ->
?len:int ->
'a t ->
segment_of:('a -> [ `Left | `Right ]) ->
[ `Last_on_left | `First_on_right ] ->
int option
val unsafe_create_uninitialized : len:int -> _ t
The behavior is undefined if you access an element before setting it.
unsafe_set_assuming_currently_int t i obj
sets index i
of t
to obj
, but only works correctly if the value there is an immediate, i.e. Stdlib.Obj.is_int (get t i)
. This precondition saves a dynamic check.
unsafe_set_int_assuming_currently_int
is similar, except the value being set is an int.
unsafe_set_int
is similar but does not assume anything about the target.
unsafe_clear_if_pointer t i
prevents t.(i)
from pointing to anything to prevent space leaks. It does this by setting t.(i)
to Stdlib.Obj.repr 0
. As a performance hack, it only does this when not (Stdlib.Obj.is_int t.(i))
. It is an error to access the cleared index before setting it again.