[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-API] [PATCH] add handy substring type
# HG changeset patch # User David Scott <dave.scott@xxxxxxxxxxxxx> # Date 1282568348 -3600 # Node ID 0adab5c36ecab8252b6f354a9b6d285d30c94254 # Parent d6b47ef01193698a7c17d2ef0ab6feaec5eeedf5 Move the handy 'substring' record type into the Zerocheck module. Signed-off-by: David Scott <dave.scott@xxxxxxxxxxxxx> diff -r d6b47ef01193 -r 0adab5c36eca stdext/zerocheck.ml --- a/stdext/zerocheck.ml Mon Aug 23 13:58:27 2010 +0100 +++ b/stdext/zerocheck.ml Mon Aug 23 13:59:08 2010 +0100 @@ -25,6 +25,12 @@ 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 @@ | 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 -r d6b47ef01193 -r 0adab5c36eca stdext/zerocheck.mli --- a/stdext/zerocheck.mli Mon Aug 23 13:58:27 2010 +0100 +++ b/stdext/zerocheck.mli Mon Aug 23 13:59:08 2010 +0100 @@ -27,8 +27,14 @@ 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 stdext/zerocheck.ml | 8 +++++++- stdext/zerocheck.mli | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) Attachment:
xen-api-libs.hg.patch _______________________________________________ xen-api mailing list xen-api@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/mailman/listinfo/xen-api
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |