Skip to content

Commit

Permalink
Add functions without side effects to ArrayVector and Vector interface
Browse files Browse the repository at this point in the history
  • Loading branch information
GollokG committed Nov 12, 2024
1 parent d789459 commit 8c23838
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/cdomains/vectorMatrix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ sig

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

val map: (num -> num) -> t -> t

val compare_length_with: t -> int -> int

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

val rev_with: t -> unit

val rev: t -> t

val map2i: (int -> num -> num -> num) -> t -> t -> t

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

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

val mapi: (int -> num -> num) -> t -> t

val find2i: (num -> num -> bool) -> t -> t -> int

val to_array: t -> num array
Expand Down Expand Up @@ -180,6 +186,8 @@ sig

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

val map2: (vec -> num -> vec) -> t -> vec -> t

val map2i: (int -> vec-> num -> vec) -> t -> vec -> t

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

let rev_with v = Array.rev_in_place v

let rev v = Array.rev v

let map_with f v = Array.modify f v

let map f v = Array.map f v

let map2_with f v1 v2 = Array.iter2i (fun i x y -> v1.(i) <- f x y) v1 v2

let map2 f v1 v2 =
let copy_v1 = copy v1 in
map2_with f copy_v1 v2; copy_v1

let copy v = Array.copy v

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

let mapi f v =
let copy = copy v in
mapi_with f copy; copy

let of_sparse_list ls col_count =
let vec = Array.make col_count A.zero in
List.iter (fun (idx, value) -> vec.(idx) <- value) ls;
Expand Down

0 comments on commit 8c23838

Please sign in to comment.