mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-01-28 11:54:51 -05:00
add Array.append
This commit is contained in:
parent
85d0ff8f3f
commit
cdb4ba5dbc
2 changed files with 23 additions and 0 deletions
|
|
@ -490,6 +490,25 @@ let filter_map f a =
|
||||||
let filter p a =
|
let filter p a =
|
||||||
filter_map (fun x -> if p x then Some x else None) a
|
filter_map (fun x -> if p x then Some x else None) a
|
||||||
|
|
||||||
|
let append a1 a2 =
|
||||||
|
let n1 = Array.length a1 in
|
||||||
|
let n2 = Array.length a2 in
|
||||||
|
if n1=0 then a2
|
||||||
|
else if n2=0 then a1
|
||||||
|
else (
|
||||||
|
let res = Array.make (n1+n2) a1.(0) in
|
||||||
|
Array.blit a1 0 res 0 n1;
|
||||||
|
Array.blit a2 0 res n1 n2;
|
||||||
|
res
|
||||||
|
)
|
||||||
|
|
||||||
|
(*$= & ~printer:Q.Print.(array int)
|
||||||
|
[| 1;2;3;4 |] (append [|1;2|] [| 3;4 |])
|
||||||
|
[| 1;2;3;4 |] (append [||] [| 1;2; 3;4 |])
|
||||||
|
[| 1;2;3;4 |] (append [| 1;2; 3;4 |] [||])
|
||||||
|
[||] (append [||] [||])
|
||||||
|
*)
|
||||||
|
|
||||||
(* append [rev a] in front of [acc] *)
|
(* append [rev a] in front of [acc] *)
|
||||||
let rec __rev_append_list a acc i =
|
let rec __rev_append_list a acc i =
|
||||||
if i = Array.length a
|
if i = Array.length a
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,10 @@ val rev : 'a t -> 'a t
|
||||||
(** Copy + reverse in place
|
(** Copy + reverse in place
|
||||||
@since 0.20 *)
|
@since 0.20 *)
|
||||||
|
|
||||||
|
val append : 'a t -> 'a t -> 'a t
|
||||||
|
(** Append 2 arrays
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val filter : ('a -> bool) -> 'a t -> 'a t
|
val filter : ('a -> bool) -> 'a t -> 'a t
|
||||||
(** Filter elements out of the array. Only the elements satisfying
|
(** Filter elements out of the array. Only the elements satisfying
|
||||||
the given predicate will be kept. *)
|
the given predicate will be kept. *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue