From 658e0cd236400c30d4df8e5be39dc84a4510f139 Mon Sep 17 00:00:00 2001 From: Calascibetta Romain Date: Mon, 6 Jan 2025 14:11:36 +0100 Subject: [PATCH] Add the shift function on Bstr --- lib/cachet.ml | 5 +++++ lib/cachet.mli | 3 +++ 2 files changed, 8 insertions(+) diff --git a/lib/cachet.ml b/lib/cachet.ml index f6d941b..cb027ba 100644 --- a/lib/cachet.ml +++ b/lib/cachet.ml @@ -391,6 +391,11 @@ module Bstr = struct match rev with | true -> rdrop ?min ?max ?sat bstr | false -> fdrop ?min ?max ?sat bstr + + let shift bstr off = + if off > length bstr then invalid_arg "Cachet.Bstr.shift"; + let len = length bstr - off in + Bigarray.Array1.sub bstr off len end external hash : (int32[@unboxed]) -> int -> (int32[@unboxed]) diff --git a/lib/cachet.mli b/lib/cachet.mli index 9a8400f..7751d3e 100644 --- a/lib/cachet.mli +++ b/lib/cachet.mli @@ -187,6 +187,9 @@ module Bstr : sig {[ (if rev then fst else snd) @@ span ~rev ~min ~max ~sat bstr ]} *) + + val shift : t -> int -> t + (** [shift bstr n] is [sub bstr n (length bstr - n)]. *) end type slice = private { offset: int; length: int; payload: Bstr.t }