Yuriy, can you give me a working example of a binary search? I can't honestly compare it to one without knowing what it should look like. This is my best guess based off the Wikipedia definition of a binary search algorithm:
Code:
First := 0;
Last := fKeywords.Count - 1;
Token := UpperCase(AKeyword);
while First <= Last do begin
Mid := (First + Last) shr 1;
Compare := CompareText(fKeywords[Mid], Token);
if Compare <0> 0 then
Last := Mid - 1
else begin
// Our result is true, force an exit.
Result := True;
exit;
end;
end;
Result := False;
However the result is the same as the old, and certain keywords are omitted. If you binary search (case-insensitive) the keyword list that follows for END_RANDOM you will not find it, and if you reorder the list that position is always missed. So, I dunno what I'm doing wrong.
Code:
CREATE_CONNECT_ALL_LANDS
CREATE_CONNECT_ALL_PLAYERS_LAND
CREATE_CONNECT_TEAMS_LANDS
CREATE_ELEVATION
CREATE_LAND
CREATE_OBJECT
CREATE_PLAYER_LANDS
CREATE_TERRAIN
DEFINE
ELSE
ELSEIF
END_RANDOM
ENDIF
GIGANTIC_MAP
HUGE_MAP
IF
LARGE_MAP
MEDIUM_MAP
PERCENT_CHANCE
REPLACE_TERRAIN
SMALL_MAP
START_RANDOM
TERRAIN_COST
TERRAIN_SIZE
TINY_MAP
?ëu?±o, yes I have reported it this morning. I waited until I had greater patience with the developers, as I did not want to abuse them over this. The urge to do so was great. Issue 0010913.
EDIT: TStringList, when sorted, uses a binary search. I have now delegated the searching to this function. I would suggest any who downloaded the prior fix to redownload it and rebuild Lazarus again; now it uses the binary search instead of a linear search.
Bookmarks