Quote Originally Posted by Robert Kosek
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.
Sure, here's an example code from our GameScripts.pas:

Code:
function TScriptObject.GetNode(ID: Cardinal): TScriptObject;
var
 Lo, Hi, Mid: Integer;
begin
 if (SearchDirty) then UpdateSearchList();

 Result:= nil;

 Lo:= 0;
 Hi:= SearchCount - 1;

 while &#40;Lo <= Hi&#41; do
  begin
   Mid&#58;= &#40;Lo + Hi&#41; div 2;

   if &#40;SearchList&#91;Mid&#93;.ID = ID&#41; then
    begin
     Result&#58;= SearchList&#91;Mid&#93;;
     Break;
    end;

   if &#40;SearchList&#91;Mid&#93;.ID > ID&#41; then Hi&#58;= Mid - 1 else Lo&#58;= Mid + 1;
 end;
end;
Remember that the list must be sorted for binary search to work.