diff --git a/core/CCArray.ml b/core/CCArray.ml index b63f8671..7de43cfe 100644 --- a/core/CCArray.ml +++ b/core/CCArray.ml @@ -110,10 +110,10 @@ let rec _foldi f acc a i j = let _reverse_in_place a i j = if i=j then () else - for k = i to j/2 do + for k = i to (j-1)/2 do let t = a.(k) in - a.(k) <- a.(j-k); - a.(j-k) <- t; + a.(k) <- a.(j-1-k); + a.(j-1-k) <- t; done let rec _equal eq a1 i1 j1 a2 i2 j2 = @@ -350,6 +350,8 @@ module Sub = struct if i+len > Array.length arr then invalid_arg "Array.Sub.make"; { arr; i; j=i+len; } + let of_slice (arr,i,len) = make arr i ~len + let full arr = { arr; i=0; j=Array.length arr; } let underlying a = a.arr diff --git a/core/CCArray.mli b/core/CCArray.mli index 7f4bd8e8..a961bd38 100644 --- a/core/CCArray.mli +++ b/core/CCArray.mli @@ -145,6 +145,11 @@ module Sub : sig (** Create a slice. @raise Invalid_argument if the slice isn't valid *) + val of_slice : ('a array * int * int) -> 'a t + (** Make a sub-array from a triple [(arr, i, len)] where [arr] is the array, + [i] the offset in [arr], and [len] the number of elements of the slice. + @raise Invalid_argument if the slice isn't valid (See {!make}) *) + val full : 'a array -> 'a t (** Slice that covers the full array *)