Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion src/dict_sorting.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Sort for dicts
import Base: sort, sort!
import Base: sort, sort!, issorted

function sort!(d::OrderedDict; byvalue::Bool=false, args...)
if d.ndel > 0
Expand Down Expand Up @@ -55,3 +55,10 @@ function sort(d::LittleDict; byvalue::Bool=false, args...)
return LittleDict(d.keys[p], d.vals[p])
end

function issorted(d::LittleDict; byvalue::Bool=false, args...)
if byvalue
return issorted(d.vals; args...)
else
return issorted(d.keys; args...)
end
end
2 changes: 2 additions & 0 deletions test/test_little_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ using OrderedCollections: FrozenLittleDict, UnfrozenLittleDict
@test collect(values(sd)) == collect('z':-1:'q')
@test sort(sd) == sd

@test !issorted(d; byvalue=true)
sdv = sort(d; byvalue=true)
@test issorted(sdv; byvalue=true)
@test collect(keys(d)) == ks # verify d is not changed by sort()
@test collect(keys(sdv)) == 10:-1:1
@test collect(values(sdv)) == collect('q':'z')
Expand Down
Loading