Skip to content

Commit 4e71240

Browse files
committed
Now that I look at it, is_stopword() is broken and always has been.
Doesn't anyone remember how to program a binary search??
1 parent 6d87107 commit 4e71240

File tree

1 file changed

+3
-4
lines changed
  • contrib/fulltextindex

1 file changed

+3
-4
lines changed

contrib/fulltextindex/fti.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,9 @@ is_stopword(char *text)
351351
StopLow = &StopWords[0]; /* initialize stuff for binary search */
352352
StopHigh = endof(StopWords);
353353

354-
if (lengthof(StopWords) == 0)
355-
return false;
354+
/* Loop invariant: *StopLow <= text < *StopHigh */
356355

357-
while (StopLow <= StopHigh)
356+
while (StopLow < StopHigh)
358357
{
359358
StopMiddle = StopLow + (StopHigh - StopLow) / 2;
360359
difference = strcmp(*StopMiddle, text);
@@ -363,7 +362,7 @@ is_stopword(char *text)
363362
else if (difference < 0)
364363
StopLow = StopMiddle + 1;
365364
else
366-
StopHigh = StopMiddle - 1;
365+
StopHigh = StopMiddle;
367366
}
368367

369368
return (false);

0 commit comments

Comments
 (0)