Something went wrong. Try again.
BSDIFF40 binary diff and patch in pure OCaml
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132(*--------------------------------------------------------------------------- Copyright (c) 2026 Thomas Gazagnaire <thomas@gazagnaire.org> SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*)
(** Suffix arrays over byte strings.
The construction is the Larsson-Sadakane qsufsort used by the reference [bsdiff] tool: bucket sort on the first byte, then rank doubling with ternary-split quicksort, O(n log n) overall. The array orders the [n + 1] suffixes of the input (including the empty suffix, which sorts first). *)
type t(** A suffix array. The input string is retained for searches. *)
val v : string -> t(** [v s] is the suffix array of [s]. *)
val length : t -> int(** [length t] is the number of suffixes, [String.length s + 1]. *)
val suffix : t -> int -> int(** [suffix t i] is the start position in [s] of the [i]-th suffix in sorted order, [0 <= i < length t]. The empty suffix is position [String.length s].*)
val longest_match : t -> target:string -> pos:int -> int * int(** [longest_match t ~target ~pos] is [(len, src_pos)]: the length of the longest common prefix between the target suffix starting at [pos] and any suffix of the indexed string, and the position of one such best-matching suffix. [len] is [0] when nothing matches. *)