Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
Delphi 10.4 Sydney
|
AW: fast array search with delphi
22. Jun 2011, 12:07
Delphi-Quellcode:
function equalpoints(p1x, p1y, p2x, p2y: integer): boolean;
begin
Result:= ((p1x = p2x) and (p1y = p2y));
end;
function IndexOfVector(const sx, sy, ex, ey: integer): integer;
var
M: integer;
begin
Result:= 0;
for M:= 1 to VNum-1 do
if equalpoints (sx, sy, V[M].sx, V[M].sy) then
if equalpoints (ex, ey, V[M].ex, V[M].ey) then
begin
Result:= M;
Break;
end;
end;
procedure removevector(mm, mm2: integer);
var
P, N: integer;
begin
P:= V[mm].prev;
V[P].next:= V[mm2].next;
N:= V[mm2].next;
V[N].prev:= P;
end;
procedure removevectors(M, M2: integer);
begin
removevector(M, M2);
removevector(M2, M);
V[M].status:= -1;
V[M2].status:= -1;
end;
procedure addsquarevector(J, K: integer);
var
M: integer;
begin
Vnum:= Vnum + 1;
V[Vnum].prev:= Vnum + 3;
V[Vnum].sx:= J;
V[Vnum].sy:= K;
V[Vnum].ex:= J + 1;
V[Vnum].ey:= K;
V[Vnum].next:= Vnum + 1;
V[Vnum].status:= 0;
M:= IndexOfVector (V[Vnum].sx, V[Vnum].sy, V[Vnum].ex, V[Vnum].ey);
if M <> 0 then
begin
removevectors(M, Vnum);
Vnum:= Vnum - 1
end;
Vnum:= Vnum + 1;
V[Vnum].prev:= Vnum - 1;
V[Vnum].sx:= J + 1;
V[Vnum].sy:= K;
V[Vnum].ex:= J + 1;
V[Vnum].ey:= K + 1;
V[Vnum].next:= Vnum + 1;
V[Vnum].status:= 0;
M:= IndexOfVector (V[Vnum].sx, V[Vnum].sy, V[Vnum].ex, V[Vnum].ey);
if M <> 0 then
begin
removevectors(M, Vnum);
Vnum:= Vnum - 1
end;
Vnum:= Vnum + 1;
V[Vnum].prev:= Vnum - 1;
V[Vnum].sx:= J + 1;
V[Vnum].sy:= K + 1;
V[Vnum].ex:= J;
V[Vnum].ey:= K + 1;
V[Vnum].next:= Vnum + 1;
V[Vnum].status:= 0;
M:= IndexOfVector (V[Vnum].sx, V[Vnum].sy, V[Vnum].ex, V[Vnum].ey);
if M <> 0 then
begin
removevectors(M, Vnum);
Vnum:= Vnum - 1
end;
Vnum:= Vnum + 1;
V[Vnum].prev:= Vnum - 1;
V[Vnum].sx:= J;
V[Vnum].sy:= K + 1;
V[Vnum].ex:= J;
V[Vnum].ey:= K;
V[Vnum].next:= Vnum - 3;
V[Vnum].status:= 0;
M:= IndexOfVector (V[Vnum].sx, V[Vnum].sy, V[Vnum].ex, V[Vnum].ey);
if M <> 0 then
begin
removevectors(M, Vnum);
Vnum:= Vnum - 1
end;
end;
Ob so aber tatsächlich eine Zeitersparnis entsteht, müßte man erst ausprobieren.
|
|
Zitat
|