Any ideas why this doesn’t work?
The call to StringSorting.quicksort!
sees all the methods of keyCompare
until the recursive call to quicksort!
when it just doesn’t anymore as it seems to call String.keyCompare
without the method addition from StringSorting.keyCompare
module Sorting
Key = Any
function keyStr end
function keyCompare end
function quicksort!(A::Array{Key},i=1,j=length(A)) where {Key}
@show keyCompare
@show methods(keyCompare)
if j > i
pivot = A[rand(i:j)] # random element of A
left, right = i, j
while left <= right
while keyCompare(A[left], pivot) == -1
left += 1
end
while keyCompare(A[right], pivot) == 1
right -= 1
end
if left <= right
A[left], A[right] = A[right], A[left]
left += 1
right -= 1
end
end
quicksort!(A,i,right)
quicksort!(A,left,j)
end
return A
end
export Key, keyStr, keyCompare, quicksort!
end
module StringSorting
using Sorting
Key = String
function keyStr(s)::String
s
end
function keyCompare(key1::String, key2::String)
if (key1 < key2) -1 elseif (key1 > key2) 1 else 0 end
end
export quicksort!, keyCompare, keyStr, Key
end
module Test
import StringSorting
function test()
A = ["84","77","20","60","47","20","18","97","41","49","31","39","73","68","65","52","1","92","15","9"]
StringSorting.quicksort!(A)
end
export test
end