summaryrefslogtreecommitdiff
path: root/AK/QuickSort.h
AgeCommit message (Collapse)Author
2021-04-28AK: Guarantee a maximum stack depth for dual_pivot_quick_sortMart G
When the two chosen pivots happen to be the smallest and largest elements of the array, three partitions will be created, two of size 0 and one of size n-2. If this happens on each recursive call to dual_pivot_quick_sort, the stack depth will reach approximately n/2. To avoid the stack from deepening, iteration can be used for the largest of the three partitions. This ensures the stack depth will only increase for partitions of size n/2 or smaller, which results in a maximum stack depth of log(n).
2021-04-28AK: Change pivot selection of dual_pivot_quick_sortMart G
Picking the first and last elements as pivots makes it so that a sorted array is the worst-case input for the algorithm. This change instead picks pivots at approximately 1/3 and 2/3 in the array. This results in desired performance for sorted arrays. Of course this only changes which inputs result in worst-case performance, but hopefully those inputs occur less frequently than already sorted arrays.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-02-01AK: Make single pivot quick_sort guarantee a max stack depth of log(n)Mart G
- The change to quick_sort requires SimpleIterator to support assignment. - Rename quick_sort to single_pivot_quick_sort to make it easier to choose a specific implementation (not based on signature). - Ensure single_pivot_quick_sort does not copy the pivots - Expand sorts_without_copy test case to cover both single and dual pivot implementations.
2020-12-10AK: Ensure dual_pivot_quick_sort does not copy the pivotsAnotherTest
Also add a test that would fail to compile if quick_sort tries to copy anything :P
2020-04-18AK: Dual pivot quicksort implementation (#1838)wilsonk
2020-03-03AK: Make quick_sort() a little more ergonomicAndreas Kling
Now it actually defaults to "a < b" comparison, instead of forcing you to provide a trivial less-than comparator. Also you can pass in any collection type that has .begin() and .end() and we'll sort it for you.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-06-07LibGUI: Run clang-format on everything.Andreas Kling
2019-05-28Add clang-format fileRobin Burchell
Also run it across the whole tree to get everything using the One True Style. We don't yet run this in an automated fashion as it's a little slow, but there is a snippet to do so in makeall.sh.
2019-05-26QuickSort: Don't sort a single item, nothing to doRobin Burchell
2019-05-19AK: Simplify quick_sort() and improve Vector iterators a bit.Andreas Kling
2019-03-09AK: Add a basic QuickSort template implementation.Andreas Kling
It was depressing not being able to capture anything when passing a lambda to qsort_r() so let's just have our own QuickSort. I was gonna have to do this eventually anyway. :^)