I just merged a major revamp of the sorting API that uses keywords to modify the ordering of elements and the algorithm used for sorting (where that applies). The sorting algorithm is controlled by the `alg` keyword (choices provided by Base are QuickSort, InsertionSort, MergeSort and TimSort; a simple BubbleSort implementation lives in examples and show how easy it is to plug a new algorithm into the framework). The ordering of elements is controlled by:
- `lt::Function=isless` to specify a custom less-than function (two arguments, returns true of the first is "less than" the second),
- `by::Function=identity` to specify a function to apply to elements before comparing them (one argument)
- `rev::Bool=false` to indicate that the normal sort ordering should be reversed.
- `order` to specify an Ordering object – this is considered advanced and may change.
Function that only take ordering keywords are:
- issorted,
- select,
- select!,
- searchsorted,
- searchsortedfirst,
- searchsortedlast.
I'd really like to get rid of searchsortedfirst and searchsortedlast – it's kind of ridiculous that so much of the API namespace is occupied by these functions. Functions that take both algorithm and ordering keywords are:
julia> words = map(chomp,readlines(open("/usr/share/dict/words")))
235886-element Any Array:
235886-element Any Array:
julia> sort(words,rev=true)
235886-element Any Array:
julia> sort(words,by=length)
235886-element Any Array:
"scientificophilosophical"
"tetraiodophenolphthalein"
"thyroparathyroidectomize"
julia> sort(words,by=length,rev=true)
235886-element Any Array:
"formaldehydesulphoxylate"
"pathologicopsychological"
"scientificophilosophical"
"tetraiodophenolphthalein"
julia> sort(words,by=length,alg=QuickSort) # unstable, words with equal length will be arbitrarily ordered
235886-element Any Array:
"formaldehydesulphoxylate"
"pathologicopsychological"
"scientificophilosophical"