Skip to content

Commit

Permalink
small tweak in findi_val_opt, could be even a tini tiny bit faster bu…
Browse files Browse the repository at this point in the history
…t not much
  • Loading branch information
CopperCableIsolator committed Dec 12, 2024
1 parent a7a4e14 commit b15b9d2
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ module SparseVector: AbstractVector =
(*Can be optimized, dont check every zero cell*)
let findi_val_opt f v =
let rec find_zero_or_val vec last_col_idx =
match vec, last_col_idx with
| [], _ -> if f A.zero && v.len <> last_col_idx + 1 then Some (last_col_idx + 1, A.zero) else None
| (idx, value) :: xs, i ->
if f A.zero && idx <> last_col_idx + 1 then Some (last_col_idx + 1, A.zero)
let f0 = f A.zero in
match vec with
| [] -> if f0 && v.len <> last_col_idx + 1 then Some (last_col_idx + 1, A.zero) else None
| (idx, value) :: xs ->
if f0 && idx <> last_col_idx + 1 then Some (last_col_idx + 1, A.zero)
else if f value then Some (idx, value)
else find_zero_or_val xs idx
in find_zero_or_val v.entries (-1)
Expand Down

0 comments on commit b15b9d2

Please sign in to comment.