Module Base.Ordered_collection_common
Functions for ordered collections.
val get_pos_len : ?pos:int -> ?len:int -> unit -> total_length:int -> (int * int) Or_error.t
get_pos_len
,get_pos_len_exn
, andcheck_pos_len_exn
are intended to be used by functions that take a sequence (array, string, bigstring, ...) and an optionalpos
andlen
specifying a subrange of the sequence. Such functions should callget_pos_len
with the length of the sequence and the optionalpos
andlen
, and it will return thepos
andlen
specifying the range, where the defaultpos
is zero and the defaultlen
is to go to the end of the sequence.It should be the case that:
pos >= 0 && len >= 0 && pos + len <= total_length
Note that this allows
pos = total_length
andlen = 0
, i.e., an empty subrange at the end of the sequence.get_pos_len
returns(pos', len')
specifying a subrange where:pos' = match pos with None -> 0 | Some i -> i len' = match len with None -> total_length - pos' | Some i -> i
val get_pos_len_exn : ?pos:int -> ?len:int -> unit -> total_length:int -> int * int
val check_pos_len_exn : pos:int -> len:int -> total_length:int -> unit
check_pos_len_exn ~pos ~len ~total_length
raises unlesspos >= 0 && len >= 0 && pos + len <= total_length
.
module Private : sig ... end