Skip to content

Commit 8c23838

Browse files
committed
Add functions without side effects to ArrayVector and Vector interface
1 parent d789459 commit 8c23838

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/cdomains/vectorMatrix.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ sig
8383

8484
val map_with: (num -> num) -> t -> unit
8585

86+
val map: (num -> num) -> t -> t
87+
8688
val compare_length_with: t -> int -> int
8789

8890
val of_list: num list -> t
@@ -99,6 +101,8 @@ sig
99101

100102
val rev_with: t -> unit
101103

104+
val rev: t -> t
105+
102106
val map2i: (int -> num -> num -> num) -> t -> t -> t
103107

104108
val map2i_with: (int -> num -> num -> num) -> t -> t -> unit
@@ -107,6 +111,8 @@ sig
107111

108112
val mapi_with: (int -> num -> num) -> t -> unit
109113

114+
val mapi: (int -> num -> num) -> t -> t
115+
110116
val find2i: (num -> num -> bool) -> t -> t -> int
111117

112118
val to_array: t -> num array
@@ -180,6 +186,8 @@ sig
180186

181187
val map2_with: (vec -> num -> vec) -> t -> vec -> unit
182188

189+
val map2: (vec -> num -> vec) -> t -> vec -> t
190+
183191
val map2i: (int -> vec-> num -> vec) -> t -> vec -> t
184192

185193
val map2i_with: (int -> vec -> num -> vec) -> t -> vec -> unit
@@ -270,14 +278,26 @@ module ArrayVector: AbstractVector =
270278

271279
let rev_with v = Array.rev_in_place v
272280

281+
let rev v = Array.rev v
282+
273283
let map_with f v = Array.modify f v
274284

285+
let map f v = Array.map f v
286+
275287
let map2_with f v1 v2 = Array.iter2i (fun i x y -> v1.(i) <- f x y) v1 v2
276288

289+
let map2 f v1 v2 =
290+
let copy_v1 = copy v1 in
291+
map2_with f copy_v1 v2; copy_v1
292+
277293
let copy v = Array.copy v
278294

279295
let mapi_with f v = Array.iteri (fun i x -> v.(i) <- f i x) v
280296

297+
let mapi f v =
298+
let copy = copy v in
299+
mapi_with f copy; copy
300+
281301
let of_sparse_list ls col_count =
282302
let vec = Array.make col_count A.zero in
283303
List.iter (fun (idx, value) -> vec.(idx) <- value) ls;

0 commit comments

Comments
 (0)