package brr

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Typed arrays.

Buffers

module Buffer : sig ... end

ArrayBuffer objects (byte buffers).

module Data_view : sig ... end

DataView objects (byte-level typed data access on ArrayBuffers).

Array types

type ('a, 'b) type' =
  1. | Int8 : (int, Bigarray.int8_signed_elt) type'
  2. | Int16 : (int, Bigarray.int16_signed_elt) type'
  3. | Int32 : (int32, Bigarray.int32_elt) type'
  4. | Uint8 : (int, Bigarray.int8_unsigned_elt) type'
  5. | Uint8_clamped : (int, Bigarray.int8_unsigned_elt) type'
  6. | Uint16 : (int, Bigarray.int16_unsigned_elt) type'
  7. | Uint32 : (int32, Bigarray.int32_elt) type'
  8. | Float32 : (float, Bigarray.float32_elt) type'
  9. | Float64 : (float, Bigarray.float64_elt) type'

The type for typed array whose elements are of type 'b and are accessed with type 'a.

val type_size_in_bytes : ('a, 'b) type' -> int

type_size_in_bytes t is the number of bytes used to store an element of type 'b.

Typed arrays

Note. In the functions below.

  • Indices can always be negative in which case they are subtracted from length. This means that -1 denotes the last element of the buffer.
  • If unspecified start defaults to 0.
  • If unspecified stop defaults to length b.
type ('a, 'b) t

The type for ArrayBufferView objects (typed access to ArrayBuffer objects) whose elements are of type 'b and accessed with type 'a. See the type aliases.

val create : ('a, 'b) type' -> int -> ('a, 'b) t

create n t is an array of type t with n elements of type 'b initialised to their zero. See also converting.

val of_buffer : ('a, 'b) type' -> ?byte_offset:int -> ?length:int -> Buffer.t -> ('a, 'b) t

of_buffer t ~byte_offset ~length b is an array of type t with length elements of type 'b starting at the byte offset byte_offset of b. byte_offset defaults to 0 and length so as to get to the end of the buffer.

val buffer : ('a, 'b) t -> Buffer.t

buffer a is the untyped buffer of a.

val byte_offset : ('a, 'b) t -> int

byte_offset a is the byte index where a starts in buffer a.

val byte_length : ('a, 'b) t -> int

byte_length a is the byte length of a.

val length : ('a, 'b) t -> int

length a are the number of elements in a.

val type' : ('a, 'b) t -> ('a, 'b) type'

type' a is the type of a.

Setting, copying and slicing

val get : ('a, 'b) t -> int -> 'a

get a i is the element of a at i.

  • deprecated Use Brr.Tarray.to_bigarray1 and operate on the bigarray instead.
val set : ('a, 'b) t -> int -> 'a -> unit

set a i v sets the element of a at i to v.

  • deprecated Use Brr.Tarray.to_bigarray1 and operate on the bigarray instead.
val set_tarray : ('a, 'b) t -> dst:int -> ('c, 'd) t -> unit

set_tarray a ~dst b sets the values of a starting at index dst with those of b which are converted to match the type of a (unclear how exactly).

val fill : ?start:int -> ?stop:int -> 'a -> ('a, 'b) t -> unit

fill ~start ~stop v a sets the elements in range [start];[stop-1] to v.

val copy_within : ?start:int -> ?stop:int -> dst:int -> ('a, 'b) t -> unit

copy_within ~start ~stop ~dst a copies at at dst the elements in range [start];[stop-1].

val slice : ?start:int -> ?stop:int -> ('a, 'b) t -> ('a, 'b) t

slice ~start ~stop a is a new array holding a copy of the bytes of a in range [start;stop-1]. This is a copy, use sub to share the data.

val sub : ?start:int -> ?stop:int -> ('a, 'b) t -> ('a, 'b) t

sub ~start ~stop a is an array that spans the bytes of b in range [start;stop-1]. This is not a copy, use slice to make a copy.

Predicates

val find : (int -> 'a -> bool) -> ('a, 'b) t -> 'a option

find sat a is the first index a.i for which sat i a.[i] is true.

val find_index : (int -> 'a -> bool) -> ('a, 'b) t -> int option

find sat a is the first index i for which sat i a.[i] is true.

val for_all : (int -> 'a -> bool) -> ('a, 'b) t -> bool

for_all sat a is true iff all elements a.[i] of b satisfy sat i a.[i].

val exists : (int -> 'a -> bool) -> ('a, 'b) t -> bool

exists sat a is true iff one elements a.[i] of b satisfies sat i a.[i].

Traversals

val filter : (int -> 'a -> bool) -> ('a, 'b) t -> ('a, 'b) t

filter sat a is an array with the elements a.[i] of a for which sat i a.[i] is true.

val iter : (int -> 'a -> unit) -> ('a, 'b) t -> unit

iter f a calls f i a.[i] on each element of a.

val map : ('a -> 'a) -> ('a, 'b) t -> ('a, 'b) t

map f a is a new typed array with elements of a mapped by f.

val fold_left : ('c -> 'a -> 'c) -> 'c -> ('a, 'b) t -> 'c

fold_left f acc a folds f over the elements of a starting with acc.

val fold_right : ('a -> 'c -> 'c) -> ('a, 'b) t -> 'c -> 'c

fold_right f acc a folds f over the elements of a starting with acc.

val reverse : ('a, 'b) t -> ('a, 'b) t

reverse a is a new array with a's elements reversed.

Type aliases

Use these in interfaces.

type int8 = (int, Bigarray.int8_signed_elt) t
type int16 = (int, Bigarray.int16_signed_elt) t
type int32 = (Int32.t, Bigarray.int32_elt) t
type uint8 = (int, Bigarray.int8_unsigned_elt) t
type uint8_clamped = (int, Bigarray.int8_unsigned_elt) t
type uint16 = (int, Bigarray.int16_unsigned_elt) t
type uint32 = (Int32.t, Bigarray.int32_elt) t
type float32 = (float, Bigarray.float32_elt) t
type float64 = (float, Bigarray.float64_elt) t

Converting

val of_tarray : ('c, 'd) type' -> ('a, 'b) t -> ('c, 'd) t

of_tarray t a is an array of type t with the elements of a converted accordingly (unclear how exactly).

val uint8_of_buffer : Buffer.t -> uint8

uint8_of_buffer b wraps b as an Uint8 typed array.

val of_int_array : ('a, 'b) type' -> int array -> ('a, 'b) t

of_int_array t arr is an array of type t whose elements are the values of arr, values exceeding the range for the type are taken modulo the range bounds (except for Uint8_clamped).

val of_float_array : ('a, 'b) type' -> float array -> ('a, 'b) t

of_int_array t arr is an array of type t whose elements are the values of arr, values exceeding the range for the type are taken modulo the range bounds (except for Uint8_clamped).

With strings

val of_jstr : Jstr.t -> uint8

of_jstr s is an unsigned byte array with s as UTF-8 encoded data.

val to_jstr : uint8 -> (Jstr.t, Jv.Error.t) result

to_jstr a is the UTF-8 encoded data a as a string. Errors if a holds invalid UTF-8.

val of_binary_jstr : Jstr.t -> (uint8, Jv.Error.t) result

of_binary_jstr s is an unsigned byte array with the bytes of the JavaScript binary string s. Errors if a code unit of s is greater than 255.

val to_binary_jstr : uint8 -> Jstr.t

to_binary_jstr a is a JavaScript binary string with the unsigned bytes of a.

val to_int_jstr : ?sep:Jstr.t -> ('a, 'b) t -> Jstr.t

to_int_jstr ~sep a is a string with the elements of a printed and separated by sep (defaults to Jstr.sp).

val to_hex_jstr : ?sep:Jstr.t -> ('a, 'b) t -> Jstr.t

to_hex_jstr ?sep a is a string with the bytes of a printed in lowercase hex and separated by sep (defaults to Jstr.empty).

val to_string : uint8 -> string

to_string a is an OCaml byte string from the byte array.

As bigarrays

val type_to_bigarray_kind : ('a, 'b) type' -> ('a, 'b) Bigarray.kind

type_to_bigarray_kind t is t as a bigarray kind. Uint32 is mapped on Bigarray.int32.

val type_of_bigarray_kind : ('a, 'b) Bigarray.kind -> ('a, 'b) type' option

type_of_bigarray_kind k is k as a type array type or None if there is no corresponding one.

val bigarray_kind : ('a, 'b) t -> ('a, 'b) Bigarray.kind

bigarray_kind a is the bigarray kind of a.

val of_bigarray1 : ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t -> ('a, 'b) t

of_bigarray1 b is a typed array with the data of bigarray b. The data buffer is shared.

val to_bigarray1 : ('a, 'b) t -> ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t

to_bigarray b is a bigarray with the data of bigarray b. The data buffer is shared.

val of_bigarray : ('a, 'b, Bigarray.c_layout) Bigarray.Genarray.t -> ('a, 'b) t

of_bigarray b is a typed array with the data of bigarray b. The data buffer is shared. XXX. How is the data laid out ?

OCaml

Innovation. Community. Security.