Skip to content

Commit

Permalink
=Fix #394
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Jul 9, 2018
1 parent a8d9477 commit 4cc80fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/dict_sorting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@ function sort!(d::OrderedDict; byvalue::Bool=false, args...)
else
p = sortperm(d.keys; args...)
end

for (i,key) in enumerate(d.keys)
idx = ht_keyindex(d, key, false)
d.slots[idx] = p[i]
end

d.keys = d.keys[p]
d.vals = d.vals[p]

rehash!(d)
return d
end

Expand Down
4 changes: 4 additions & 0 deletions test/test_sorting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
@test sort(unordered; rev=true) == rev
@test sort(unordered; byvalue=true) == rev
@test sort(unordered; byvalue=true, rev=true) == forward

@testset "Bug DataStructures.jl/#394" begin
@test sort(Dict(k=>string(k) for k in 1:3))[1] == "1"
end
end

0 comments on commit 4cc80fb

Please sign in to comment.