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:
@@ -3,7 +3,7 @@ struct
|
||||
local
|
||||
fun reverseLinearSearch (findNum, idx, vec) =
|
||||
if idx < 0 then
|
||||
idx
|
||||
~1
|
||||
else
|
||||
let
|
||||
val curVal = Vector.sub (vec, idx)
|
||||
@@ -38,7 +38,7 @@ struct
|
||||
local
|
||||
fun forwardLinearSearch (findNum, idx, vec) =
|
||||
if idx = Vector.length vec then
|
||||
idx
|
||||
~1
|
||||
else
|
||||
let
|
||||
val curVal = Vector.sub (vec, idx)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -262,7 +262,7 @@ struct
|
||||
else
|
||||
let
|
||||
val pos = BinSearch.equalOrMore (cursorIdx + 1, searchList)
|
||||
val pos = if pos < Vector.length searchList then pos else 0
|
||||
val pos = if pos = ~1 then 0 else pos
|
||||
val count = count - 1
|
||||
in
|
||||
loopNextMatch (pos, searchList, count)
|
||||
@@ -286,7 +286,7 @@ struct
|
||||
else
|
||||
let
|
||||
val pos = BinSearch.equalOrLess (cursorIdx - 1, searchList)
|
||||
val pos = if pos < 0 then Vector.length searchList - 1 else pos
|
||||
val pos = if pos = ~1 then Vector.length searchList - 1 else pos
|
||||
val count = count - 1
|
||||
in
|
||||
loopPrevMatch (pos, searchList, count)
|
||||
|
||||
@@ -29,7 +29,10 @@ struct
|
||||
Utils.getRelativeLineStartFromRightHead (startLine, curLine, lhd)
|
||||
(* get absolute idx of line *)
|
||||
val absIdx = curIdx + strPos
|
||||
|
||||
val searchPos = BinSearch.equalOrMore (absIdx, searchList)
|
||||
val searchPos =
|
||||
if searchPos = ~1 then Vector.length searchList else searchPos
|
||||
|
||||
val env = Utils.initEnv
|
||||
( windowWidth
|
||||
|
||||
@@ -60,7 +60,7 @@ struct
|
||||
let
|
||||
val searchPos = BinSearch.equalOrMore (pos + 1, #searchList env)
|
||||
in
|
||||
if searchPos = Vector.length line then
|
||||
if searchPos = ~1 then
|
||||
(* next line is not in this node *)
|
||||
let
|
||||
val absIdx = absIdx - pos
|
||||
|
||||
@@ -75,7 +75,7 @@ struct
|
||||
let
|
||||
val searchPos = BinSearch.equalOrMore (pos + 1, #searchList env)
|
||||
in
|
||||
if searchPos = Vector.length line then
|
||||
if searchPos = ~1 then
|
||||
(* next line is not in this node *)
|
||||
let
|
||||
val absIdx = absIdx - pos
|
||||
|
||||
Reference in New Issue
Block a user