Skip to content

Commit

Permalink
Merge f186dde into 3e666ec
Browse files Browse the repository at this point in the history
  • Loading branch information
ranjanan committed Jul 28, 2016
2 parents 3e666ec + f186dde commit b9d8771
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/SortingAlgorithms.jl
@@ -1,6 +1,7 @@
module SortingAlgorithms

using Compat
import Compat.view
using Base.Sort
using Base.Order

Expand All @@ -22,7 +23,7 @@ const RadixSort = RadixSortAlg()

function sort!(v::AbstractVector, lo::Int, hi::Int, a::HeapSortAlg, o::Ordering)
if lo > 1 || hi < length(v)
return sort!(sub(v, lo:hi), 1, length(v), a, o)
return sort!(view(v, lo:hi), 1, length(v), a, o)
end
r = ReverseOrdering(o)
heapify!(v, r)
Expand Down Expand Up @@ -548,7 +549,7 @@ function sort!(v::AbstractVector, lo::Int, hi::Int, ::TimSortAlg, o::Ordering)
else
if !issorted(run_range)
run_range = last(run_range):first(run_range)
reverse!(sub(v, run_range))
reverse!(view(v, run_range))
end
end
# Push this run onto the queue and merge if needed
Expand Down
1 change: 1 addition & 0 deletions test/REQUIRE
@@ -0,0 +1 @@
StatsBase 0.9.0
5 changes: 3 additions & 2 deletions test/runtests.jl
@@ -1,6 +1,7 @@
using Base.Test
using SortingAlgorithms
using Compat
using StatsBase

a = rand(1:10000, 1000)

Expand Down Expand Up @@ -56,14 +57,14 @@ srand(0xdeadbeef)
for n in [0:10..., 100, 101, 1000, 1001]
r = 1:10
v = rand(1:10,n)
h = hist(v,r)
h = fit(Histogram, v, r)

for ord in [Base.Order.Forward, Base.Order.Reverse]
# insertion sort (stable) as reference
pi = sortperm(v, alg=InsertionSort, order=ord)
@test isperm(pi)
si = v[pi]
@test hist(si,r) == h
@test fit(Histogram, si, r) == h
@test issorted(si, order=ord)
@test all(issorted,[pi[si.==x] for x in r])
c = copy(v)
Expand Down

0 comments on commit b9d8771

Please sign in to comment.