1
+ __precompile__ ()
2
+
1
3
module SortingAlgorithms
2
4
3
5
using Compat
6
+ using DataStructures
4
7
import Compat. view
5
8
using Base. Sort
6
9
using Base. Order
7
10
8
11
import Base. Sort: sort!
9
- import Base . Collections : heapify!, percolate_down!
12
+ import DataStructures : heapify!, percolate_down!
10
13
11
14
export HeapSort, TimSort, RadixSort
12
15
45
48
uint_mapping (:: ForwardOrdering , x:: Unsigned ) = x
46
49
for (signedty, unsignedty) in ((Int8, UInt8), (Int16, UInt16), (Int32, UInt32), (Int64, UInt64), (Int128, UInt128))
47
50
# In Julia 0.4 we can just use unsigned() here
48
- @eval uint_mapping (:: ForwardOrdering , x:: $signedty ) = reinterpret ($ unsignedty, x $ typemin (typeof (x)))
51
+ @eval uint_mapping (:: ForwardOrdering , x:: $signedty ) = reinterpret ($ unsignedty, xor (x, typemin (typeof (x) )))
49
52
end
50
- uint_mapping (:: ForwardOrdering , x:: Float32 ) = (y = reinterpret (Int32, x); reinterpret (UInt32, ifelse (y < 0 , ~ y, y $ typemin (Int32))))
51
- uint_mapping (:: ForwardOrdering , x:: Float64 ) = (y = reinterpret (Int64, x); reinterpret (UInt64, ifelse (y < 0 , ~ y, y $ typemin (Int64))))
53
+ uint_mapping (:: ForwardOrdering , x:: Float32 ) = (y = reinterpret (Int32, x); reinterpret (UInt32, ifelse (y < 0 , ~ y, xor (y, typemin (Int32) ))))
54
+ uint_mapping (:: ForwardOrdering , x:: Float64 ) = (y = reinterpret (Int64, x); reinterpret (UInt64, ifelse (y < 0 , ~ y, xor (y, typemin (Int64) ))))
52
55
53
56
uint_mapping {Fwd} (rev:: ReverseOrdering{Fwd} , x) = ~ uint_mapping (rev. fwd, x)
54
57
uint_mapping {T<:Real} (:: ReverseOrdering{ForwardOrdering} , x:: T ) = ~ uint_mapping (Forward, x) # maybe unnecessary; needs benchmark
@@ -65,7 +68,7 @@ function sort!(vs::AbstractVector, lo::Int, hi::Int, ::RadixSortAlg, o::Ordering
65
68
if lo >= hi; return vs; end
66
69
67
70
# Make sure we're sorting a bits type
68
- T = ordtype (o, vs)
71
+ T = Base . Order . ordtype (o, vs)
69
72
if ! isbits (T)
70
73
error (" Radix sort only sorts bits types (got $T )" )
71
74
end
134
137
#
135
138
# Original author: @kmsquire
136
139
137
- typealias Run UnitRange{Int}
140
+ const Run = UnitRange{Int}
138
141
139
142
const MIN_GALLOP = 7
140
143
0 commit comments