Module Base_bigstringSource
String type based on Bigarray, for use in I/O and C-bindings.
Types and exceptions
type t =
(Base.char, Stdlib.Bigarray.int8_unsigned_elt, Stdlib.Bigarray.c_layout)
Stdlib.Bigarray.Array1.tType of bigstrings
include Ppx_compare_lib.Comparable.S with type t := Base_bigstring.t
include Ppx_compare_lib.Equal.S with type t := Base_bigstring.t
include Sexplib0.Sexpable.S with type t := Base_bigstring.t
include Sexplib0.Sexpable.Of_sexp with type t := Base_bigstring.t
include Sexplib0.Sexpable.Sexp_of with type t := Base_bigstring.t
Type of bigstrings which support hashing. Note that mutation invalidates previous hashes.
include sig ... end
val compare_t_frozen__local :
Base_bigstring.t_frozen @ read ->
Base_bigstring.t_frozen @ read ->
Base.intval equal_t_frozen__local :
Base_bigstring.t_frozen @ read ->
Base_bigstring.t_frozen @ read ->
Base.boolval hash_fold_t_frozen :
Ppx_hash_lib.Std.Hash.state ->
Base_bigstring.t_frozen ->
Ppx_hash_lib.Std.Hash.stateCreation and string conversion
create length
empty is a bigstring of length 0
init n ~f creates a bigstring t of length n, with t.{i} = f i.
val of_string :
?pos:Base.int ->
?len:Base.int ->
Base.string @ read ->
Base_bigstring.t @@ portableof_string ?pos ?len str
val of_bytes :
?pos:Base.int ->
?len:Base.int ->
Base.bytes @ read read ->
Base_bigstring.t @@ portableof_bytes ?pos ?len str
val to_string :
?pos:Base.int ->
?len:Base.int ->
Base_bigstring.t @ read read ->
Base.string @@ portableto_string ?pos ?len bstr
val to_bytes :
?pos:Base.int ->
?len:Base.int ->
Base_bigstring.t @ read read ->
Base.bytes @@ portableto_bytes ?pos ?len bstr
val concat :
?sep:Base_bigstring.t @ read read ->
Base_bigstring.t Base.list @ read read ->
Base_bigstring.t @@ portableconcat ?sep list returns the concatenation of list with sep in between each.
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
val check_args :
loc:Base.string ->
pos:Base.int ->
len:Base.int ->
Base_bigstring.t @ read immutable ->
Base.unit @@ portablecheck_args ~loc ~pos ~len bstr checks the position and length arguments pos and len for bigstrings bstr.
val get_opt_len :
Base_bigstring.t @ read immutable ->
pos:Base.int ->
Base.int Base.option @ read ->
Base.int @@ portableget_opt_len bstr ~pos opt_len
Accessors
length bstr
get t pos returns the character at pos
unsafe_get t pos returns the character at pos, without bounds checks.
set t pos sets the character at pos
unsafe_set t pos sets the character at pos, without bounds checks.
is_mmapped bstr
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 ->
unitval blito :
src:Base_bigstring.t @ local local ->
?src_pos:int ->
?src_len:int ->
dst:Base_bigstring.t @ local ->
?dst_pos:int ->
unit ->
unitval unsafe_blit :
src:Base_bigstring.t @ local local ->
src_pos:int ->
dst:Base_bigstring.t @ local ->
dst_pos:int ->
len:int ->
unitval sub :
Base_bigstring.t @ local local ->
pos:int ->
len:int ->
Base_bigstring.tval subo :
?pos:int ->
?len:int ->
Base_bigstring.t @ local local ->
Base_bigstring.tmodule From_string :
Base.Blit.S_distinct
with type src := Base.string
with type dst := Base_bigstring.tmodule To_bytes :
Base.Blit.S_distinct__read
with type src := Base_bigstring.t
with type dst := Base.bytesmodule From_bytes :
Base.Blit.S_distinct__read
with type src := Base.bytes
with type dst := Base_bigstring.tval memset :
Base_bigstring.t @ read ->
pos:Base.int ->
len:Base.int ->
Base.char ->
Base.unit @@ portablememset t ~pos ~len c fills t with c within the range [pos, pos + len).
val unsafe_memset :
Base_bigstring.t @ read ->
pos:Base.int ->
len:Base.int ->
Base.char ->
Base.unit @@ portableunsafe_memset t ~pos ~len c fills t with c within the range [pos, pos + len), without bounds checks.
Memcmp
val memcmp :
Base_bigstring.t @ read read ->
pos1:Base.int ->
Base_bigstring.t @ read read ->
pos2:Base.int ->
len:Base.int ->
Base.int @@ portablememcmp 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.
val memcmp_bytes :
Base_bigstring.t @ read read ->
pos1:Base.int ->
Base.Bytes.t @ read read ->
pos2:Base.int ->
len:Base.int ->
Base.int @@ portablememcmp_bytes, for efficient memcmp between Bigstring and Bytes data.
val memcmp_string :
Base_bigstring.t @ read read ->
pos1:Base.int ->
Base.string @ read read ->
pos2:Base.int ->
len:Base.int ->
Base.int @@ portablememcmp_string, for efficient memcmp between Bigstring and string data.
val unsafe_strncmp :
Base_bigstring.t @ read ->
pos1:Base.int ->
Base_bigstring.t @ read ->
pos2:Base.int ->
len:Base.int ->
Base.int @@ portableCompares 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.
Search
val find :
?pos:Base.int ->
?len:Base.int ->
Base.char ->
Base_bigstring.t @ read read ->
Base.int Base.option @@ portablefind ?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.
val rfind :
?pos:Base.int ->
?len:Base.int ->
Base.char ->
Base_bigstring.t @ read read ->
Base.int Base.option @@ portablerfind ?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.
val unsafe_find :
Base_bigstring.t @ read ->
Base.char ->
pos:Base.int ->
len:Base.int ->
Base.int @@ portableSame as find, but does no bounds checking, and returns a negative value instead of None if char is not found.
val unsafe_rfind :
Base_bigstring.t @ read ->
Base.char ->
pos:Base.int ->
len:Base.int ->
Base.int @@ portableSame as rfind, but does no bounds checking, and returns a negative value instead of None if char is not found.
val 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 @@ portableSearch for the position of (a substring of) needle in (a substring of) haystack.
val 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 @@ portableAs 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.val set_int8_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval set_uint8_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_set_int8 :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_set_uint8 :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portable16-bit methods
val set_int16_le_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval set_int16_be_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_get_int16_le :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_get_int16_be :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_set_int16_le :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_set_int16_be :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval set_uint16_le_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval set_uint16_be_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_get_uint16_le :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_get_uint16_be :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_set_uint16_le :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_set_uint16_be :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portable32-bit methods
val set_int32_le_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval set_int32_be_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_get_int32_le :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_get_int32_be :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_set_int32_le :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_set_int32_be :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval set_uint32_le_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval set_uint32_be_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_get_uint32_le :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_get_uint32_be :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_set_uint32_le :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_set_uint32_be :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableSimilar 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
val set_int64_le :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval set_int64_be :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_get_int64_le_exn :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_get_int64_be_exn :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_get_int64_le_trunc :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_get_int64_be_trunc :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_set_int64_le :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_set_int64_be :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portable64-bit unsigned values
val set_uint64_le_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval set_uint64_be_exn :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_get_uint64_be_exn :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_get_uint64_le_exn :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.int @@ portableval unsafe_set_uint64_le :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portableval unsafe_set_uint64_be :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.int ->
Base.unit @@ portable32-bit methods with full precision
val set_int32_t_le :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.Int32.t @ read ->
Base.unit @@ portableval set_int32_t_be :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.Int32.t @ read ->
Base.unit @@ portableval unsafe_get_int32_t_le :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.Int32.t @@ portableval unsafe_get_int32_t_be :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.Int32.t @@ portableval unsafe_set_int32_t_le :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.Int32.t @ read ->
Base.unit @@ portableval unsafe_set_int32_t_be :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.Int32.t @ read ->
Base.unit @@ portable64-bit methods with full precision
val set_int64_t_le :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.Int64.t @ read ->
Base.unit @@ portableval set_int64_t_be :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.Int64.t @ read ->
Base.unit @@ portableval unsafe_get_int64_t_le :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.Int64.t @@ portableval unsafe_get_int64_t_be :
Base_bigstring.t @ read read ->
pos:Base.int ->
Base.Int64.t @@ portableval unsafe_set_int64_t_le :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.Int64.t @ read ->
Base.unit @@ portableval unsafe_set_int64_t_be :
Base_bigstring.t @ read ->
pos:Base.int ->
Base.Int64.t @ read ->
Base.unit @@ portableString methods
These are alternatives to to_string that follow the conventions of the int accessors, and in particular avoid optional arguments.
val get_string :
Base_bigstring.t @ read read ->
pos:Base.int ->
len:Base.int ->
Base.string @@ portableval unsafe_get_string :
Base_bigstring.t @ read read ->
pos:Base.int ->
len:Base.int ->
Base.string @@ portable