Merge pull request #159 from orbifx/master

Add `CCImmutArray.sub`, which creates a copy
This commit is contained in:
Simon Cruanes 2017-11-20 21:45:57 +01:00 committed by GitHub
commit 170d7662e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View file

@ -27,6 +27,8 @@ let set a n x =
a'.(n) <- x;
a'
let sub = Array.sub (* Would this not be better implemented with CCArray_slice *)
let map = Array.map
let mapi = Array.mapi

View file

@ -36,6 +36,15 @@ val get : 'a t -> int -> 'a
val set : 'a t -> int -> 'a -> 'a t
(** Copy the array and modify its copy *)
val sub : 'a t -> int -> int -> 'a t
(** [sub a start len] returns a fresh array of length len, containing the elements
from [start] to pstart + len - 1] of array a.
Raises [Invalid_argument "Array.sub"] if [start] and [len] do not designate a
valid subarray of a; that is, if start < 0, or len < 0, or start + len > Array.length a.
@since NEXT_RELEASE *)
val map : ('a -> 'b) -> 'a t -> 'b t
val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t