You've already forked lazarus-ccr
CalLite: Use binary search in TCalDateList (patch by howardpc). Some cleanup.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5342 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -515,16 +515,33 @@ begin
|
||||
end;
|
||||
|
||||
function TCalDateList.IndexOfDate(ADate: TDate): Integer;
|
||||
// to do: Since the list is always ordered use a binary search here
|
||||
var
|
||||
i: Integer;
|
||||
lower, higher, mid, truncADate, truncMidDate: integer;
|
||||
|
||||
function Compare: integer;
|
||||
begin
|
||||
if (truncMidDate < truncADate) then
|
||||
Exit(-1)
|
||||
else if (truncMidDate > truncADate) then
|
||||
Exit(+1)
|
||||
else
|
||||
Exit(0);
|
||||
end;
|
||||
|
||||
begin
|
||||
for i:=0 to FList.Count-1 do
|
||||
if SameDate(GetDate(i), ADate) then begin
|
||||
Result := i;
|
||||
exit;
|
||||
lower := 0;
|
||||
higher := Pred(FList.Count);
|
||||
truncADate := trunc(ADate);
|
||||
while (lower <= higher) do begin
|
||||
mid := (lower + higher) shr 1;
|
||||
truncMidDate:=trunc(GetDate(mid));
|
||||
case Compare of
|
||||
-1: lower := Succ(mid);
|
||||
+1: higher := Pred(mid);
|
||||
0: Exit(mid);
|
||||
end;
|
||||
Result := -1;
|
||||
end;
|
||||
Exit(-1);
|
||||
end;
|
||||
|
||||
procedure TCalDateList.Insert(AIndex: Integer; ADate: TDate);
|
||||
|
Reference in New Issue
Block a user