jon.recoil.org

Module Base_bigstringSource

String type based on Bigarray, for use in I/O and C-bindings.

Types and exceptions

Sourceval t_sexp_grammar : Base_bigstring.t Sexplib0.Sexp_grammar.t @@ portable
Sourceval globalize : Base_bigstring.t @ read read -> Base_bigstring.t @@ portable
Sourcetype t_frozen = Base_bigstring.t

Type of bigstrings which support hashing. Note that mutation invalidates previous hashes.

Creation and string conversion

Sourceval create : Base.int -> Base_bigstring.t @@ portable

create length

  • returns

    a new bigstring having length. Content is undefined.

Sourceval empty : Base_bigstring.t @@ portable

empty is a bigstring of length 0

Sourceval init : Base.int -> f:(Base.int -> Base.char) -> Base_bigstring.t @@ portable

init n ~f creates a bigstring t of length n, with t.{i} = f i.

Sourceval of_string : ?pos:Base.int -> ?len:Base.int -> Base.string @ read -> Base_bigstring.t @@ portable

of_string ?pos ?len str

  • returns

    a new bigstring that is equivalent to the substring of length len in str starting at position pos.

  • parameter pos

    default = 0

  • parameter len

    default = String.length str - pos

Sourceval of_bytes : ?pos:Base.int -> ?len:Base.int -> Base.bytes @ read read -> Base_bigstring.t @@ portable

of_bytes ?pos ?len str

  • returns

    a new bigstring that is equivalent to the subbytes of length len in str starting at position pos.

  • parameter pos

    default = 0

  • parameter len

    default = Bytes.length str - pos

Sourceval to_string : ?pos:Base.int -> ?len:Base.int -> Base_bigstring.t @ read read -> Base.string @@ portable

to_string ?pos ?len bstr

  • returns

    a new string that is equivalent to the substring of length len in bstr starting at position pos.

  • parameter pos

    default = 0

  • parameter len

    default = length bstr - pos

Sourceval to_bytes : ?pos:Base.int -> ?len:Base.int -> Base_bigstring.t @ read read -> Base.bytes @@ portable

to_bytes ?pos ?len bstr

  • returns

    a new byte sequence that is equivalent to the substring of length len in bstr starting at position pos.

  • parameter pos

    default = 0

  • parameter len

    default = length bstr - pos

Sourceval concat : ?sep:Base_bigstring.t @ read read -> Base_bigstring.t Base.list @ read read -> Base_bigstring.t @@ portable

concat ?sep list returns the concatenation of list with sep in between each.

Sourceval unsafe_globalize_shared : Base_bigstring.t @ read -> Base_bigstring.t @@ portable

Like globalize, but does not copy the bigstring. Returns the input unchanged, as all bigstrings are allocated on the heap as custom blocks.

May be unsafe to hold on to the bigstring and access its storage if the source of the local value overwrites or deletes its storage later.

Checking

Sourceval check_args : loc:Base.string -> pos:Base.int -> len:Base.int -> Base_bigstring.t @ read immutable -> Base.unit @@ portable

check_args ~loc ~pos ~len bstr checks the position and length arguments pos and len for bigstrings bstr.

  • raises

    Invalid_argument if these arguments are illegal for the given bigstring using loc to indicate the calling context.

Sourceval get_opt_len : Base_bigstring.t @ read immutable -> pos:Base.int -> Base.int Base.option @ read -> Base.int @@ portable

get_opt_len bstr ~pos opt_len

  • returns

    the length of a subbigstring in bstr starting at position pos and given optional length opt_len. This function does not check the validity of its arguments. Use check_args for that purpose.

Accessors

Sourceval length : Base_bigstring.t @ read immutable -> Base.int @@ portable

length bstr

  • returns

    the length of bigstring bstr.

Sourceval get : Base_bigstring.t @ read -> Base.int -> Base.char @@ portable

get t pos returns the character at pos

Sourceval unsafe_get : Base_bigstring.t @ read -> Base.int -> Base.char @@ portable

unsafe_get t pos returns the character at pos, without bounds checks.

Sourceval set : Base_bigstring.t -> Base.int -> Base.char -> Base.unit @@ portable

set t pos sets the character at pos

Sourceval unsafe_set : Base_bigstring.t -> Base.int -> Base.char -> Base.unit @@ portable

unsafe_set t pos sets the character at pos, without bounds checks.

Sourceval is_mmapped : Base_bigstring.t @ immutable -> Base.bool @@ portable

is_mmapped bstr

  • returns

    whether the bigstring bstr is memory-mapped.

Blitting

blit ~src ?src_pos ?src_len ~dst ?dst_pos () blits src_len characters from src starting at position src_pos to dst at position dst_pos.

include Base.Blit.S__read with type t := Base_bigstring.t
val blit : src:Base_bigstring.t @ local local -> src_pos:int -> dst:Base_bigstring.t @ local -> dst_pos:int -> len:int -> unit
val blito : src:Base_bigstring.t @ local local -> ?src_pos:int -> ?src_len:int -> dst:Base_bigstring.t @ local -> ?dst_pos:int -> unit -> unit
val unsafe_blit : src:Base_bigstring.t @ local local -> src_pos:int -> dst:Base_bigstring.t @ local -> dst_pos:int -> len:int -> unit
val sub : Base_bigstring.t @ local local -> pos:int -> len:int -> Base_bigstring.t
val subo : ?pos:int -> ?len:int -> Base_bigstring.t @ local local -> Base_bigstring.t
Sourceval copy : Base_bigstring.t @ read read -> Base_bigstring.t @@ portable
Sourcemodule To_string : sig ... end
Sourceval memset : Base_bigstring.t @ read -> pos:Base.int -> len:Base.int -> Base.char -> Base.unit @@ portable

memset t ~pos ~len c fills t with c within the range [pos, pos + len).

Sourceval unsafe_memset : Base_bigstring.t @ read -> pos:Base.int -> len:Base.int -> Base.char -> Base.unit @@ portable

unsafe_memset t ~pos ~len c fills t with c within the range [pos, pos + len), without bounds checks.

Memcmp

Sourceval memcmp : Base_bigstring.t @ read read -> pos1:Base.int -> Base_bigstring.t @ read read -> pos2:Base.int -> len:Base.int -> Base.int @@ portable

memcmp t1 ~pos1 t2 ~pos2 ~len is like compare t1 t2 except performs the comparison on the subregions of t1 and t2 defined by pos1, pos2, and len.

Sourceval memcmp_bytes : Base_bigstring.t @ read read -> pos1:Base.int -> Base.Bytes.t @ read read -> pos2:Base.int -> len:Base.int -> Base.int @@ portable

memcmp_bytes, for efficient memcmp between Bigstring and Bytes data.

Sourceval memcmp_string : Base_bigstring.t @ read read -> pos1:Base.int -> Base.string @ read read -> pos2:Base.int -> len:Base.int -> Base.int @@ portable

memcmp_string, for efficient memcmp between Bigstring and string data.

Sourceval unsafe_strncmp : Base_bigstring.t @ read -> pos1:Base.int -> Base_bigstring.t @ read -> pos2:Base.int -> len:Base.int -> Base.int @@ portable

Compares up to len characters of two (potentially null-terminated) strings beginning at pos1 and pos2 of their respective Bigstrings. This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ, until a terminating null-character is reached, or until len characters match in both strings, whichever happens first.

unsafe_strncmp does no bounds checking.

Sourceval find : ?pos:Base.int -> ?len:Base.int -> Base.char -> Base_bigstring.t @ read read -> Base.int Base.option @@ portable

find ?pos ?len char t returns Some i for the smallest i >= pos such that t.{i} = char, or None if there is no such i.

  • parameter pos

    default = 0

  • parameter len

    default = length bstr - pos

Sourceval rfind : ?pos:Base.int -> ?len:Base.int -> Base.char -> Base_bigstring.t @ read read -> Base.int Base.option @@ portable

rfind ?pos ?len char t returns Some i for the largest i >= pos such that t.{i} = char, or None if there is no such i.

  • parameter pos

    default = 0

  • parameter len

    default = length bstr - pos

Sourceval unsafe_find : Base_bigstring.t @ read -> Base.char -> pos:Base.int -> len:Base.int -> Base.int @@ portable

Same as find, but does no bounds checking, and returns a negative value instead of None if char is not found.

Sourceval unsafe_rfind : Base_bigstring.t @ read -> Base.char -> pos:Base.int -> len:Base.int -> Base.int @@ portable

Same as rfind, but does no bounds checking, and returns a negative value instead of None if char is not found.

Sourceval memmem : haystack:Base_bigstring.t @ read read -> needle:Base_bigstring.t @ read read -> ?haystack_pos:Base.int -> ?haystack_len:Base.int -> ?needle_pos:Base.int -> ?needle_len:Base.int -> Base.unit -> Base.int Base.option @@ portable

Search for the position of (a substring of) needle in (a substring of) haystack.

Sourceval unsafe_memmem : haystack:Base_bigstring.t @ read -> needle:Base_bigstring.t @ read -> haystack_pos:Base.int -> haystack_len:Base.int -> needle_pos:Base.int -> needle_len:Base.int -> Base.int @@ portable

As unsafe_find for memmem.

{2 Accessors for parsing binary values, analogous to [Binary_packing]}

   These are in [Bigstring] rather than a separate module because:

   1. Existing [Binary_packing] requires copies and does not work with [bigstring]s.
   2. The accessors rely on the implementation of [bigstring], and hence should change
   should the implementation of [bigstring] move away from [Bigarray].
   3. [Bigstring] already has some external C functions, so it didn't require many
   changes to the [jbuild] ^_^.

   In a departure from [Binary_packing], the naming conventions are chosen to be close to
   C99 stdint types, as it's a more standard description and it is somewhat useful in
   making compact macros for the implementations.  The accessor names contain endian-ness
   to allow for branch-free implementations

   <accessor>  ::= <unsafe><operation><type><endian>
   <unsafe>    ::= unsafe_ | ''
   <operation> ::= get_ | set_
   <type>      ::= int8 | uint8 | int16 | uint16 | int32 | uint32 | int64 | uint64
   <endian>    ::= _le | _be | ''

   The [unsafe_] prefix indicates that these functions do no bounds checking and silently
   truncate out-of-range numeric arguments.
Sourceval get_int8 : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval set_int8_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval get_uint8 : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval set_uint8_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_get_int8 : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_set_int8 : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_get_uint8 : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_set_uint8 : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable

16-bit methods

Sourceval get_int16_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval get_int16_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval set_int16_le_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval set_int16_be_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_get_int16_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_get_int16_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_set_int16_le : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_set_int16_be : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval get_uint16_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval get_uint16_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval set_uint16_le_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval set_uint16_be_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_get_uint16_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_get_uint16_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_set_uint16_le : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_set_uint16_be : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable

32-bit methods

Sourceval get_int32_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval get_int32_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval set_int32_le_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval set_int32_be_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_get_int32_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_get_int32_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_set_int32_le : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_set_int32_be : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval get_uint32_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval get_uint32_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval set_uint32_le_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval set_uint32_be_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_get_uint32_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_get_uint32_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_set_uint32_le : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_set_uint32_be : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable

Similar to the usage in binary_packing, the below methods are treating the value being read (or written), as an ocaml immediate integer, as such it is actually 63 bits. If the user is confident that the range of values used in practice will not require 64-bit precision (i.e. Less than Max_Long), then we can avoid allocation and use an immediate. If the user is wrong, an exception will be thrown (for get).

64-bit signed values

Sourceval get_int64_le_exn : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval get_int64_be_exn : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval get_int64_le_trunc : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval get_int64_be_trunc : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval set_int64_le : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval set_int64_be : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_get_int64_le_exn : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_get_int64_be_exn : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_get_int64_le_trunc : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_get_int64_be_trunc : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_set_int64_le : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_set_int64_be : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable

64-bit unsigned values

Sourceval get_uint64_be_exn : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval get_uint64_le_exn : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval set_uint64_le_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval set_uint64_be_exn : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_get_uint64_be_exn : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_get_uint64_le_exn : Base_bigstring.t @ read read -> pos:Base.int -> Base.int @@ portable
Sourceval unsafe_set_uint64_le : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable
Sourceval unsafe_set_uint64_be : Base_bigstring.t @ read -> pos:Base.int -> Base.int -> Base.unit @@ portable

32-bit methods with full precision

Sourceval get_int32_t_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.Int32.t @@ portable
Sourceval get_int32_t_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.Int32.t @@ portable
Sourceval set_int32_t_le : Base_bigstring.t @ read -> pos:Base.int -> Base.Int32.t @ read -> Base.unit @@ portable
Sourceval set_int32_t_be : Base_bigstring.t @ read -> pos:Base.int -> Base.Int32.t @ read -> Base.unit @@ portable
Sourceval unsafe_get_int32_t_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.Int32.t @@ portable
Sourceval unsafe_get_int32_t_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.Int32.t @@ portable
Sourceval unsafe_set_int32_t_le : Base_bigstring.t @ read -> pos:Base.int -> Base.Int32.t @ read -> Base.unit @@ portable
Sourceval unsafe_set_int32_t_be : Base_bigstring.t @ read -> pos:Base.int -> Base.Int32.t @ read -> Base.unit @@ portable

64-bit methods with full precision

Sourceval get_int64_t_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.Int64.t @@ portable
Sourceval get_int64_t_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.Int64.t @@ portable
Sourceval set_int64_t_le : Base_bigstring.t @ read -> pos:Base.int -> Base.Int64.t @ read -> Base.unit @@ portable
Sourceval set_int64_t_be : Base_bigstring.t @ read -> pos:Base.int -> Base.Int64.t @ read -> Base.unit @@ portable
Sourceval unsafe_get_int64_t_le : Base_bigstring.t @ read read -> pos:Base.int -> Base.Int64.t @@ portable
Sourceval unsafe_get_int64_t_be : Base_bigstring.t @ read read -> pos:Base.int -> Base.Int64.t @@ portable
Sourceval unsafe_set_int64_t_le : Base_bigstring.t @ read -> pos:Base.int -> Base.Int64.t @ read -> Base.unit @@ portable
Sourceval unsafe_set_int64_t_be : Base_bigstring.t @ read -> pos:Base.int -> Base.Int64.t @ read -> Base.unit @@ portable

String methods

These are alternatives to to_string that follow the conventions of the int accessors, and in particular avoid optional arguments.

Sourceval get_string : Base_bigstring.t @ read read -> pos:Base.int -> len:Base.int -> Base.string @@ portable
Sourceval unsafe_get_string : Base_bigstring.t @ read read -> pos:Base.int -> len:Base.int -> Base.string @@ portable
Sourcemodule Local : sig ... end
Sourcemodule Int_repr : sig ... end
Sourcemodule Private : sig ... end