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;
|
end;
|
||||||
|
|
||||||
function TCalDateList.IndexOfDate(ADate: TDate): Integer;
|
function TCalDateList.IndexOfDate(ADate: TDate): Integer;
|
||||||
// to do: Since the list is always ordered use a binary search here
|
|
||||||
var
|
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
|
begin
|
||||||
for i:=0 to FList.Count-1 do
|
lower := 0;
|
||||||
if SameDate(GetDate(i), ADate) then begin
|
higher := Pred(FList.Count);
|
||||||
Result := i;
|
truncADate := trunc(ADate);
|
||||||
exit;
|
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;
|
end;
|
||||||
Result := -1;
|
end;
|
||||||
|
Exit(-1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalDateList.Insert(AIndex: Integer; ADate: TDate);
|
procedure TCalDateList.Insert(AIndex: Integer; ADate: TDate);
|
||||||
|
Reference in New Issue
Block a user