Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Added timsort, plus misc. sort updates #1691

Merged
merged 25 commits into from
Dec 18, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
70f1d78
Added timsort, plus misc. sort updates
kmsquire Dec 6, 2012
2cfe1c8
Fixes to make tests pass.
kmsquire Dec 6, 2012
f96546d
Remove *sort_lt functions; the *sort functions are overloaded
kmsquire Dec 7, 2012
951aba1
Partially implement timsort with index permutation (incomplete).
kmsquire Dec 8, 2012
6ac2e2f
Finished implementing timsort with index permutations.
kmsquire Dec 8, 2012
47eeff7
timsort: actually return the permutation
kmsquire Dec 8, 2012
672641e
Be less clever about functions working with a permutation.
kmsquire Dec 8, 2012
091a00e
Small changes to merge_collapse().
kmsquire Dec 8, 2012
cc1b777
Minor updates to timsort.
kmsquire Dec 10, 2012
7153958
Export *sort! functions; parameterize merge_compute_minrun()
kmsquire Dec 10, 2012
928d82f
Add missing commas to export.
kmsquire Dec 10, 2012
4226bd5
Modularize Sort
kmsquire Dec 10, 2012
edb873c
Import required functions from Base into Sort
kmsquire Dec 11, 2012
efd852e
Added nonmutating forms of *sort
kmsquire Dec 14, 2012
6ae4f4c
Filled out *sort_perm functions.
kmsquire Dec 14, 2012
df779f6
Added missing insertionsort_perm, timsort_perm definitions.
kmsquire Dec 14, 2012
e3a715b
Updated exports, tests.
kmsquire Dec 15, 2012
a838111
Reinstated exports from Sort module (but not Base)
kmsquire Dec 15, 2012
d26cb7e
Updated sort documentation.
kmsquire Dec 15, 2012
c85fdb7
Moved each_row, each_col, and each_vec from sort.jl to AbstractArray.jl
kmsquire Dec 15, 2012
478862e
Updated sort tests.
kmsquire Dec 15, 2012
532482d
In docs, move sort after base, instead of in extras.
kmsquire Dec 15, 2012
141a2b1
Define sorts with @eval instead of macro, to match c6a3c85.
kmsquire Dec 18, 2012
644b0fb
Merge branch 'master' into timsort
kmsquire Dec 18, 2012
fca6052
(Pushed too quickly... removed extraneous <<<<<< HEAD from merge)
kmsquire Dec 18, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,34 @@ indices(I::(Indices...)) = map(indices, I)

## iteration utilities ##

# TODO: something sensible should happen when each_col et. al. are used with a
# pure function argument
function each_col!(f::Function, a::AbstractMatrix)
m = size(a,1)
for i = 1:m:numel(a)
f(sub(a, i:(i+m-1)))
end
return a
end

function each_row!(f::Function, a::AbstractMatrix)
m = size(a,1)
for i = 1:m
f(sub(a, i:m:numel(a)))
end
return a
end

function each_vec!(f::Function, a::AbstractMatrix, dim::Integer)
if dim == 1; return each_col!(f,a); end
if dim == 2; return each_row!(f,a); end
error("invalid matrix dimensions: ", dim)
end

each_col(f::Function, a::AbstractMatrix) = each_col!(f,copy(a))
each_row(f::Function, a::AbstractMatrix) = each_row!(f,copy(a))
each_vec(f::Function, a::AbstractMatrix, d::Integer) = each_vec!(f,copy(a),d)

# slow, but useful
function cartesian_map(body, t::(Int...), it...)
idx = length(t)-length(it)
Expand Down
2 changes: 2 additions & 0 deletions base/combinatorics.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Sort.@in_place_matrix_op

function factorial(n::Integer)
if n < 0
return zero(n)
Expand Down
23 changes: 23 additions & 0 deletions base/export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ export
ipermute,
isperm,
issorted,
issorted_r,
issorted_by,
last,
linspace,
logspace,
Expand Down Expand Up @@ -618,10 +620,20 @@ export
rotl90,
rotr90,
search_sorted,
search_sorted_r,
search_sorted_by,
search_sorted_first,
search_sorted_first_r,
search_sorted_first_by,
search_sorted_last,
search_sorted_last_r,
search_sorted_last_by,
select,
select_r,
select_by,
select!,
select_r!,
select_by!,
shuffle,
shuffle!,
size,
Expand All @@ -632,6 +644,7 @@ export
sort_by,
sort_by!,
sortperm,
sortperm!,
sortr,
sortr!,
squeeze,
Expand All @@ -652,6 +665,16 @@ export
make_loop_nest,
check_bounds,

# sort routines
insertionsort,
insertionsort!,
quicksort,
quicksort!,
mergesort,
mergesort!,
timsort,
timsort!,

# linear algebra
axpy,
chol,
Expand Down
Loading