Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CopperCableIsolator committed Dec 27, 2024
1 parent de6acc7 commit c01b627
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/cdomains/affineEquality/sparseImplementation/sparseVector.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,55 @@ module SparseVector: AbstractVector =
let entries' = v.entries @ List.map (fun (idx, value) -> (idx + v.len), value) v'.entries in
{entries = entries'; len = v.len + v'.len}

let exists f v = (*TODO: optimize!; maybe we shouldn't if exists is never called with a =: A.zero*)
let c = v.len in
let rec exists_aux at f v =
match v with
| [] -> if at = 0 then false else f A.zero
| (xi, xv)::xs -> if f xv then true else exists_aux (at - 1) f xs
in (exists_aux c f v.entries)

let exists2 f v1 v2 = (* TODO: optimize! *)
List.exists2 f (to_list v1) (to_list v2)

let rev v =
let entries' = List.rev @@ List.map (fun (idx, value) -> (v.len - 1 - idx, value)) v.entries in
{entries = entries'; len = v.len}

let find2i f v v' = (* TODO: optimize! *) (*"Franzisco should do this!":~Franzisco*)
fst @@ List.findi (fun _ (val1, val2) -> (uncurry f) (val1, val2)) (List.combine (to_list v) (to_list v'))

let to_array v =
let vec = Array.make v.len A.zero in
List.iter (fun (idx, value) -> vec.(idx) <- value) v.entries;
vec

let of_array a =
let len' = Array.length a in
let entries' = List.rev @@ Array.fold_lefti (fun acc i x -> if x <> A.zero then (i, x) :: acc else acc ) [] a in
{entries = entries'; len = len'}

let copy v = v

let of_sparse_list col_count ls =
{entries = ls; len = col_count}

let to_sparse_list v =
v.entries

let find_opt f v = (* TODO: Do we need this? And optimize!!!*)
List.find_opt f (to_list v)

let starting_from_nth n v =
let entries' = List.filter_map (fun (idx, value) -> if idx < n then None else Some (idx - n, value)) v.entries in
{entries = entries'; len = v.len - n}

let show v =
let t = to_list v in
let rec list_str l =
match l with
| [] -> "]"
| x :: xs -> (A.to_string x) ^ " " ^ (list_str xs)
in
"["^list_str t^"\n"
end

0 comments on commit c01b627

Please sign in to comment.