mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-27 03:36:39 +00:00
* binary search can be tricky. I hope I got it right now.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23230 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b6be7d908f
commit
7c5d585c84
@ -620,8 +620,7 @@ void GuiCompleter::setCurrentCompletion(QString const & s)
|
||||
// In sorted models, do binary search for s.
|
||||
i = 0;
|
||||
size_t r = n - 1;
|
||||
int c;
|
||||
do {
|
||||
while (r >= i && i < n) {
|
||||
size_t mid = (r + i) / 2;
|
||||
QString const & mids
|
||||
= model.data(model.index(mid, 0),
|
||||
@ -630,22 +629,23 @@ void GuiCompleter::setCurrentCompletion(QString const & s)
|
||||
// left or right?
|
||||
// FIXME: is this really the same order that the docstring
|
||||
// from the CompletionList has?
|
||||
c = s.compare(mids, Qt::CaseSensitive);
|
||||
int c = s.compare(mids, Qt::CaseSensitive);
|
||||
if (c == 0) {
|
||||
i = mid;
|
||||
break;
|
||||
} else if (i == r) {
|
||||
i = n;
|
||||
break;
|
||||
} else if (c > 0)
|
||||
// middle is not far enough
|
||||
i = mid + 1;
|
||||
else
|
||||
// middle is too far
|
||||
r = mid;
|
||||
r = mid - 1;
|
||||
}
|
||||
|
||||
} while (r - i > 0 && i < n);
|
||||
|
||||
// loop was left with failed comparison?
|
||||
// i.e. word was not found.
|
||||
if (c != 0)
|
||||
// loop was left without finding anything
|
||||
if (r < i)
|
||||
i = n;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user