package shexp

  1. Overview
  2. Docs

Module Shexp_bigstring.BigstringSource

Bigstring helpers for shexp libraries

Sourceval create : int -> t
Sourceval length : t -> int
Sourceval blit : src:t -> src_pos:int -> dst:t -> dst_pos:int -> len:int -> unit
Sourceval blit_string_t : src:string -> src_pos:int -> dst:t -> dst_pos:int -> len:int -> unit
Sourceval blit_t_bytes : src:t -> src_pos:int -> dst:Bytes.t -> dst_pos:int -> len:int -> unit
Sourceval sub_string : t -> pos:int -> len:int -> string
Sourceval index : t -> pos:int -> len:int -> char:char -> int option
Sourceval rindex : t -> pos:int -> len:int -> char:char -> int option
Sourceval pos_len_ok : pos:int -> len:int -> length:int -> bool

Efficiently checks that the range denoted by (pos, len) is in the range 0..length. length is assumed to be >= 0.

Sourceval check_pos_len_exn : pos:int -> len:int -> length:int -> unit

Raises if (pos, len) denotes a range outside of 0..length.

Sourceval with_temporary : size:int -> f:(t -> 'a) -> 'a

Allocate a bigstring and pass it to f. The memory allocated for the bigstring is released as soon as f returns. As such, the bigstring shouldn't be used after f returns.

This is more efficient than waiting on the garbage collector to release the external memory.

Sourcetype ('a, 'b) fold_temporary_result =
  1. | Resize of {
    1. new_size : int;
    2. state : 'a;
    }
  2. | Continue of {
    1. state : 'a;
    }
    (*

    Same as Resize with the same size

    *)
  3. | Return of 'b
Sourceval fold_temporary : size:int -> init:'a -> f:(t -> 'a -> ('a, 'b) fold_temporary_result) -> 'b

Same as with_temporary, but allow to resize the bigstring if needed.

If f returns Resize { new_size; state }, the bigstring will be resized to the given new size and f will be called with the new bigstring and state. The contents of the bigstring up to the min of the old and new sizes is preserved.

OCaml

Innovation. Community. Security.