You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/SortingAlgorithms.jl
+42-1Lines changed: 42 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9,16 +9,43 @@ using Base.Order
9
9
import Base.Sort: sort!
10
10
import DataStructures: heapify!, percolate_down!
11
11
12
-
export HeapSort, TimSort, RadixSort
12
+
export HeapSort, TimSort, RadixSort, CombSort
13
13
14
14
struct HeapSortAlg <:Algorithmend
15
15
struct TimSortAlg <:Algorithmend
16
16
struct RadixSortAlg <:Algorithmend
17
+
struct CombSortAlg <:Algorithmend
17
18
18
19
const HeapSort =HeapSortAlg()
19
20
const TimSort =TimSortAlg()
20
21
const RadixSort =RadixSortAlg()
21
22
23
+
"""
24
+
CombSort
25
+
26
+
Indicates that a sorting function should use the comb sort
27
+
algorithm. Comb sort traverses the collection multiple times
28
+
ordering pairs of elements with a given interval between them.
29
+
The interval decreases exponentially until it becomes 1, then
30
+
it switches to insertion sort on the whole input.
31
+
32
+
Characteristics:
33
+
- *not stable* does not preserve the ordering of elements which
34
+
compare equal (e.g. "a" and "A" in a sort of letters which
35
+
ignores case).
36
+
- *in-place* in memory.
37
+
- *parallelizable* suitable for vectorization with SIMD instructions
38
+
because it performs many independent comparisons.
39
+
- *pathological inputs* such as `repeat(1:5.0, 4^8)` can make this algorithm perform very poorly.
40
+
- *`n log n` average runtime* measured for random inputs of length up to 100 million, but theoretical runtime of `Θ(n^2)` for extremely long inputs.
41
+
42
+
## References
43
+
- Dobosiewicz, Wlodzimierz, (1980). "An efficient variation of bubble sort", Information Processing Letters, 11(1), pp. 5-6, https://doi.org/10.1016/0020-0190(80)90022-8.
44
+
- Werneck, N. L., (2020). "ChipSort: a SIMD and cache-aware sorting module. JuliaCon Proceedings, 1(1), 12, https://doi.org/10.21105/jcon.00012
45
+
- H. Inoue, T. Moriyama, H. Komatsu and T. Nakatani, "AA-Sort: A New Parallel Sorting Algorithm for Multi-Core SIMD Processors," 16th International Conference on Parallel Architecture and Compilation Techniques (PACT 2007), 2007, pp. 189-198, doi: 10.1109/PACT.2007.4336211.
46
+
"""
47
+
const CombSort =CombSortAlg()
48
+
22
49
23
50
## Heap sort
24
51
@@ -578,4 +605,18 @@ function sort!(v::AbstractVector, lo::Int, hi::Int, ::TimSortAlg, o::Ordering)
0 commit comments