From cb7835dd9934c6a6daa133092c543ad877d624d2 Mon Sep 17 00:00:00 2001 From: David Scott Date: Mon, 23 Aug 2010 13:59:08 +0100 Subject: [PATCH] Move the handy 'substring' record type into the Zerocheck module. Signed-off-by: David Scott --- stdext/zerocheck.ml | 8 +++++++- stdext/zerocheck.mli | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/stdext/zerocheck.ml b/stdext/zerocheck.ml index 2cb956b..7c1f46b 100644 --- a/stdext/zerocheck.ml +++ b/stdext/zerocheck.ml @@ -25,6 +25,12 @@ let wrap f x len offset = let find_a_nonzero = wrap _find_a_nonzero let find_a_zero = wrap _find_a_zero +type substring = { + buf: string; + offset: int; + len: int +} + let fold_over_nonzeros x len roundup f initial = let rec inner acc offset = if offset = len then acc @@ -36,6 +42,6 @@ let fold_over_nonzeros x len roundup f initial = | None -> len | Some e -> e in let e = min len (roundup e) in - inner (f acc (s, e - s)) e in + inner (f acc { buf = x; offset = s; len = e - s }) e in inner initial 0 diff --git a/stdext/zerocheck.mli b/stdext/zerocheck.mli index 0e09540..472ebab 100644 --- a/stdext/zerocheck.mli +++ b/stdext/zerocheck.mli @@ -27,8 +27,14 @@ val find_a_zero: string -> int -> int -> int option strictly the first nonzero. *) val find_a_nonzero: string -> int -> int -> int option +type substring = { + buf: string; + offset: int; + len: int +} + (** [fold_over_nonzeros buf len roundup f initial] folds [f] over all (start, length) pairs of non-zero data in string [buf] up to [len]. The end offset of each pair is rounded up with [roundup] (e.g. to potential block boudaries. *) -val fold_over_nonzeros: string -> int -> (int -> int) -> ('a -> int * int -> 'a) -> 'a -> 'a +val fold_over_nonzeros: string -> int -> (int -> int) -> ('a -> substring -> 'a) -> 'a -> 'a -- 2.39.5