]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
Move the handy 'substring' record type into the Zerocheck module.
authorDavid Scott <dave.scott@eu.citrix.com>
Mon, 23 Aug 2010 12:59:08 +0000 (13:59 +0100)
committerDavid Scott <dave.scott@eu.citrix.com>
Mon, 23 Aug 2010 12:59:08 +0000 (13:59 +0100)
Signed-off-by: David Scott <dave.scott@eu.citrix.com>
stdext/zerocheck.ml
stdext/zerocheck.mli

index 2cb956b01c88e33fb5e6c011ea7ba0439c20cfd9..7c1f46ba5f6985d47ef6428781620d95d04f52b3 100644 (file)
@@ -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
 
index 0e095403230bc2b49f2330115c9ee79f78993c56..472ebab7fa1346c7d330926cbfb6c74263950f0f 100644 (file)
@@ -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