mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-28 17:20:30 +02:00
* select the middle element in the default quicksort implementation in a way
that doesn't generate arithmetic overflow for very large arrays git-svn-id: trunk@41241 -
This commit is contained in:
parent
e467d2387d
commit
00a67caa40
@ -94,7 +94,7 @@ begin
|
||||
repeat
|
||||
I := L;
|
||||
J := R;
|
||||
PivotIdx := (L + R) div 2;
|
||||
PivotIdx := L + ((R - L) shr 1); { same as ((L + R) div 2), but without the possibility of overflow }
|
||||
P := ItemPtrs[PivotIdx];
|
||||
repeat
|
||||
while (I < PivotIdx) and (Comparer(P, ItemPtrs[i]) > 0) do
|
||||
@ -161,7 +161,7 @@ procedure QuickSort_PtrList_Context(ItemPtrs: PPointer; ItemCount: SizeUInt; Com
|
||||
repeat
|
||||
I := L;
|
||||
J := R;
|
||||
PivotIdx := (L + R) div 2;
|
||||
PivotIdx := L + ((R - L) shr 1); { same as ((L + R) div 2), but without the possibility of overflow }
|
||||
P := ItemPtrs[PivotIdx];
|
||||
repeat
|
||||
while (I < PivotIdx) and (Comparer(P, ItemPtrs[I], Context) > 0) do
|
||||
@ -230,7 +230,7 @@ var
|
||||
repeat
|
||||
I := L;
|
||||
J := R;
|
||||
PivotIdx := (L + R) div 2;
|
||||
PivotIdx := L + ((R - L) shr 1); { same as ((L + R) div 2), but without the possibility of overflow }
|
||||
P := Items + ItemSize*PivotIdx;
|
||||
repeat
|
||||
while (I < PivotIdx) and (Comparer(P, Items + ItemSize*I, Context) > 0) do
|
||||
@ -308,7 +308,7 @@ procedure QuickSort_ItemList_CustomItemExchanger_Context(
|
||||
repeat
|
||||
I := L;
|
||||
J := R;
|
||||
PivotIdx := (L + R) div 2;
|
||||
PivotIdx := L + ((R - L) shr 1); { same as ((L + R) div 2), but without the possibility of overflow }
|
||||
P := Items + ItemSize*PivotIdx;
|
||||
repeat
|
||||
while (I < PivotIdx) and (Comparer(P, Items + ItemSize*I, Context) > 0) do
|
||||
|
Loading…
Reference in New Issue
Block a user