Commit Graph

21 Commits

Author SHA1 Message Date
Michael VAN CANNEYT
ccfa38c68e * Dotted RTL compiles 2023-07-27 19:04:03 +02:00
florian
931d4dcfee * ensure the rtl and the packages for embedded compile with features exceptions and classes disabled
git-svn-id: trunk@43931 -
2020-01-13 21:20:03 +00:00
nickysn
1c64f4c751 * some formatting changes to avoid very large lines in the source code
git-svn-id: trunk@41242 -
2019-02-06 18:26:05 +00:00
nickysn
00a67caa40 * 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 -
2019-02-06 18:05:48 +00:00
nickysn
f4718831ca * fixed quicksort comment about memory use - our implementation uses O(log n) stack, not O(n log n)
git-svn-id: trunk@41236 -
2019-02-06 12:22:08 +00:00
nickysn
f32748a8e7 + added comment with information about QuickSort and its specific implementation in unit SortBase
git-svn-id: trunk@41232 -
2019-02-05 18:02:48 +00:00
nickysn
eca60a0a89 * partition elements equal to the pivot on both sides of the pivot, since that
leads to much better performance when sorting lots of repeating elements

git-svn-id: trunk@41231 -
2019-02-05 17:32:28 +00:00
nickysn
bea9961d2d * use SizeUInt instead of longint for the array indices in the quicksort
implementations. This:
  1) allows sorting arrays with >4G elements on 64-bit systems
  2) allows sorting arrays with up to 4G (>2G) elements on 32-bit systems
  3) uses 16-bit instead of the less efficient 32-bit indices on 16-bit and
     8-bit platforms

git-svn-id: trunk@41230 -
2019-02-05 16:20:56 +00:00
nickysn
f5f25f7ae6 * use a more robust QuickSort implementation, that is guaranteed to never loop
forever and never access index out of bounds elements from the array when
  being passed an incorrect comparison function. The resulting sort order is
  still undefined in this case, though.

git-svn-id: trunk@41229 -
2019-02-05 16:00:42 +00:00
nickysn
de80621e1e * use a try..finally block to protect against memory leaks if the comparison
callback function raises an exception in QuickSort_ItemList_Context

git-svn-id: trunk@41228 -
2019-02-05 12:14:09 +00:00
nickysn
26486bbaea + keep track of the pivot index in all quicksort implementations. No functional changes,
but will be used to prevent overlap in the divided subregions and also infinite loops
  in case of an incorrect compare function.

git-svn-id: trunk@41222 -
2019-02-04 15:32:41 +00:00
nickysn
ea340b9481 * fixed bug in QuickSort_ItemList_CustomItemExchanger_Context and
QuickSort_ItemList_Context and which can cause wrong sort results, due to not
  taking into account that the pivot can be moved by the swap operation

git-svn-id: trunk@41191 -
2019-02-03 16:34:05 +00:00
nickysn
c7d8bd9666 + added a sort algorithm interface that accepts a custom callback function for
exchanging two elements. This is required for TStringList.Sort (and is the
  most generic form for a sort algorithm interface that I can think of).

git-svn-id: trunk@41182 -
2019-02-03 00:33:43 +00:00
nickysn
59a75ea429 * use Inc() and Dec() instead of v:=v+1
git-svn-id: trunk@41178 -
2019-02-02 22:58:52 +00:00
nickysn
4082b8c7fc + added and implemented QuickSort_ItemList_Context
git-svn-id: trunk@41175 -
2019-02-02 21:21:07 +00:00
nickysn
7f44f2535e * the Compare parameter renamed Comparer for consistency
git-svn-id: trunk@41174 -
2019-02-02 21:08:30 +00:00
nickysn
8cf5779297 * the first parameter of QuickSort_PtrList_NoContext renamed ItemPtrs for
consistency with the other similar procedures

git-svn-id: trunk@41173 -
2019-02-02 21:07:27 +00:00
nickysn
a2a0ed53b2 * the type of the ItemCount parameter changed from PtrUInt to SizeUInt
git-svn-id: trunk@41172 -
2019-02-02 21:05:02 +00:00
nickysn
848890e54b + added the TItemListSorter_NoContext and TItemListSorter_Context procedure
types to sortbase. No implementation for them yet. They will allow sorting
  an array with elements of arbitrary size (e.g. array of records).

git-svn-id: trunk@41171 -
2019-02-02 21:03:10 +00:00
nickysn
25f6da7066 * added PtrList to the names of the current sort algorithm callback functions and
types, to indicate they sort a list of pointers

git-svn-id: trunk@41170 -
2019-02-02 20:56:59 +00:00
nickysn
248fd313f8 + introduced unit SortBase, which implements the foundation for pluggable
sorting algorithms. A default QuickSort implementation is provided by the
  unit. Other units can be added, to provide other sorting algorithms (e.g.
  HeapSort, MergeSort, IntroSort, etc.)
* TList and TFPList updated to use the current default sorting algorithm defined
  in SortBase for their .Sort method.

git-svn-id: trunk@41167 -
2019-02-02 20:06:50 +00:00