lisp2arx
Visual Programming for AutoLisp
Mathématiques en programmation Lisp..
doc2cpp,doc2lsp, sld2lsp, bmp2dcl,
free__GifCcapture for all-CAD'platforms..
|
Nou pe simpatie: beatrice17 pe Simpatie.ro
 | Femeie 25 ani Bucuresti cauta Barbat 25 - 80 ani |
|
|
lisp2arxReguliInregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
|
| #1 |
adminAdministratorDin: Bucharest
Postari: 523
|
|
I need xchg for all-types-variabile., but the function xchg_han() have bugs Xchg_han crash and he do not swap values. Please help me... Xchg(I,j) is alias Exchange(I, J); How can I implement a quick sort in Delphi without getting Access violation errors for large numbers of records?
Code:
type
HMODULE= Cardinal; { HMODULEs can be used in place of HINSTs }
LHANDLE=HMODULE;
PLHANDLE=^HMODULE;
type tap_idaloadintv6=record
str:shortstring; // index
are:double;
sub:byte;
call:integer;
retw:word; //serial16
end;
Var HashTable:array[word] of tap_idaloadintv6;
Function xchg_han(a,b:pchar;extmin:word):boolean;
Var gap,nth:integer;swapOrder:dow;
Begin result:=false;
if (a=nil) or (b=nil) then exit else result:=true;
if (extmin>3) then
Begin gap:=extmin and 3;
extmin:=extmin shr 2;
for nth:=1 to extmin do
Begin swapOrder:=PLHANDLE(a)^;
PLHANDLE(a)^:=PLHANDLE(b)^;
PLHANDLE(b)^:=swapOrder;
inc(a);inc(a);inc(a);inc(a);
inc(b);inc(b);inc(b);inc(b);
End
End
else gap:=extmin;
for nth:=0 to gap do Begin extmin:=ord(a^);
a^:=b^;
b^:=chr(extmin);
inc(a);inc(b);
End;
End;
Function QSort_HashTable(LowJitters,HighJitters:Integer):TrueBool;
Var p1,p2:pchar;
procedure QuickSort(iLo, iHi: Integer);
var Lo, Hi, Mid: Integer;
begin
Lo := iLo;
Hi := iHi;
Mid := HashTable[(Lo + Hi) div 2].nn_call;
repeat
while HashTable[Lo].nn_call < Mid do Inc(Lo);
while HashTable[Hi].nn_call > Mid do Dec(Hi);
if (Lo <= Hi)
(xchg_han(@(HashTable[Hi],@HashTable[lo],sizeof(tap_idaloadintv6))
then
Begin
Inc(Lo);
Dec(Hi);
end;
until Lo > Hi;
if Hi > iLo then QuickSort(iLo, Hi);
if Lo < iHi then QuickSort(Lo, iHi);
end;
begin
if (LowJitters>HighJitters) then xchg_int(LowJitters,HighJitters);
QuickSort(LowJitters,HighJitters);
result:=true;
end; |
Initialization
Code:
Initialization
fillchar(HashTable,sizeof(HashTable),0); |
_______________________________________ http://www.puiubrat.3x.ro/lisp2arx/lisp ... O2UTM2.pdf
|
|
| |
|
| pus acum 5 zile#2 |
Lisp2CppC+Lisp basicInregistrat: acum 7 zile
Postari: 4
|
|
Eu as renunta complet la toata chinezaria cu pchar/PLHANDLE si la manipularea octet cu octet pentru un record Delphi. Cauza probabila a crash-ului e tocmai incrementarea gresita a pointerilor si conversiile necompatibile (si posibil campuri "managed" tratate ca memorie bruta). In Delphi pentru un record simplu (fara campuri string dinamice, interfete, variante etc.) cel mai simplu si sigur e fie o assign printr-un record temporar, fie Move cu un buffer alocat. De exemplu, cel mai clar si robust swap e: temp := HashTable[i]; HashTable[i] := HashTable[j]; HashTable[j] := temp; Delphi se ocupa singur de copierea corecta a campurilor. Daca tot vrei o functie generica pe pointeri, foloseste PByte si GetMem/FreeMem: GetMem(buf, Size); Move(ptrA^, buf^, Size); Move(ptrB^, ptrA^, Size); Move(buf^, ptrB^, Size); FreeMem(buf); dar atentie: asta NU e sigur pentru campuri gestionate de runtime (ansistring, dynamic array, interface, variant) - pentru ele trebuie assignment de tipul Delphi. In plus, in QuickSort as folosi indexi Integer si SwapRecord(var A,B: tap_idaloadintv6) din exemplu de mai sus. Verifica limitele (Low/High) si pivoti corect, si evita sa folosesti caractere ca pointeri la record. Daca vrei, pot scrie un exemplu concret de QuickSort cu SwapRecord pentru tipul tau de record.
|
|
| |
|