in BinSearch.equalOrMore and BinSearch.equalOrLess, return ~1 if no item is found, for the sake of less ambiguity in usage. Functions that call these have also been adapted.

This commit is contained in:
2025-09-13 02:18:14 +01:00
parent 53a4265b07
commit 20a542df29
6 changed files with 17 additions and 7 deletions

View File

@@ -29,7 +29,13 @@ struct
val linePos = BinSearch.equalOrLess (strPos - 1, lhd)
val lineIdx = Vector.sub (lhd, linePos)
in
absIdx - strPos + lineIdx + 1
if linePos = ~1 then
(* no previous line in lhd *)
helpVi0 (absIdx - strPos, stl, ltl)
else
let val lineIdx = Vector.sub (lhd, linePos)
in absIdx - strPos + lineIdx + 1
end
end
else
helpVi0 (absIdx - strPos, stl, ltl)
@@ -224,6 +230,7 @@ struct
* because we know lnHd definitely contains
* a lineIdx less or equal to strIdx *)
let
(* todo: what if BinSearch doesn't find anything? *)
val lnIdx = BinSearch.equalOrLess (strIdx, lnHd)
val lnIdx = Vector.sub (lnHd, lnIdx)
in