From: Olivier S. <ob...@us...> - 2005-08-11 16:07:18
|
Update of /cvsroot/jvcl/dev/JVCL3/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29454/dev/JVCL3/run Modified Files: JvJCLUtils.pas Log Message: Added CollectionSort Index: JvJCLUtils.pas =================================================================== RCS file: /cvsroot/jvcl/dev/JVCL3/run/JvJCLUtils.pas,v retrieving revision 1.155 retrieving revision 1.156 diff -C2 -d -r1.155 -r1.156 *** JvJCLUtils.pas 2 Aug 2005 19:36:46 -0000 1.155 --- JvJCLUtils.pas 11 Aug 2005 16:07:05 -0000 1.156 *************** *** 1193,1196 **** --- 1193,1201 ---- {$ENDIF COMPILER5} + type + TCollectionSortProc = function(Item1, Item2: TCollectionItem): Integer; + + procedure CollectionSort(Collection: TCollection; sortProc: TCollectionSortProc); + {$IFDEF UNITVERSIONING} const *************** *** 9695,9698 **** --- 9700,9751 ---- {$ENDIF COMPILER5} + procedure CollectionQuickSort(List: TCollection; L, R: Integer; sortProc: TCollectionSortProc); + var + I, J, pix: Integer; + P, t1, t2: TCollectionItem; + begin + List.BeginUpdate; + repeat + I := L; + J := R; + pix := (L+R) shr 1; + if pix> List.Count-1 then pix := List.Count-1; + P := List.Items[pix]; + + repeat + + while sortProc(List.Items[I], P) < 0 do Inc(I); + while sortProc(List.Items[J], P) > 0 do Dec(J); + + if I <= J then + begin + t1 := List.Items[I]; + t2 := List.Items[J]; + t1.Index := J; + t2.Index := I; + + if pix = I then pix := J + else if pix = J then pix:=I; + + P := List.Items[pix]; + Inc(I); + Dec(J); + end; + until I > J; + if L < J then + CollectionQuickSort(List, L, J, sortProc); + L := I; + until I>=R; + List.EndUpdate; + end; + + procedure CollectionSort(Collection: TCollection; sortProc: TCollectionSortProc); + begin + if not Assigned(Collection) then Exit; + if not Assigned(sortProc) then Exit; + CollectionQuickSort(Collection, 0, Collection.Count-1, sortProc); + end; + + {$IFDEF UNITVERSIONING} initialization |