ccpersistentArray.copy

This commit is contained in:
Simon Cruanes 2015-03-24 12:21:14 +01:00
parent adee01be65
commit 76f966aed3
2 changed files with 6 additions and 1 deletions

View file

@ -49,6 +49,8 @@ let reroot t = match !t with
| Array a -> a
| _ -> _reroot t (fun x -> x)
let copy t = ref (Array(Array.copy (reroot t)))
let get t i = match !t with
| Array a -> a.(i)
| _ -> (reroot t).(i)

View file

@ -65,9 +65,12 @@ val set : 'a t -> int -> 'a -> 'a t
val length : 'a t -> int
(** Returns the length of the persistent array. *)
val copy : 'a t -> 'a t
(** [copy a] returns a fresh copy of [a]. Both copies are independent. *)
val map : ('a -> 'b) -> 'a t -> 'b t
val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t
(** Applies the given function to all elements of the array, and returns
(** Applies the given function to all elements of the array, and returns
a persistent array initialized by the results of f. In the case of [mapi],
the function is also given the index of the element.
It is equivalent to [fun f t -> init (fun i -> f (get t i))]. *)