Skip to content

Change Dict to be ordered by default #38145

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

Closed
Closed
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
6 changes: 5 additions & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ using .Multimedia
# Some type
include("some.jl")

include("dict.jl")
#TODO:
include("dict.jl") # better named udict.jl?
#include("udict.jl")
include("ordered_dict.jl") # provides the new Dict implementation

include("abstractset.jl")
include("set.jl")

Expand Down
36 changes: 18 additions & 18 deletions base/abstractdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ julia> merge!(d1, d2);

julia> d1
Dict{Int64, Int64} with 3 entries:
4 => 5
3 => 4
1 => 4
3 => 4
4 => 5
```
"""
function merge!(d::AbstractDict, others::AbstractDict...)
Expand Down Expand Up @@ -210,23 +210,23 @@ julia> mergewith!(+, d1, d2);

julia> d1
Dict{Int64, Int64} with 3 entries:
4 => 5
3 => 4
1 => 6
3 => 4
4 => 5

julia> mergewith!(-, d1, d1);

julia> d1
Dict{Int64, Int64} with 3 entries:
4 => 0
3 => 0
1 => 0
3 => 0
4 => 0

julia> foldl(mergewith!(+), [d1, d2]; init=Dict{Int64, Int64}())
Dict{Int64, Int64} with 3 entries:
4 => 5
3 => 0
1 => 4
3 => 0
4 => 5
```
"""
function mergewith!(combine, d::AbstractDict, others::AbstractDict...)
Expand Down Expand Up @@ -282,24 +282,24 @@ value for that key will be the value it has in the last collection listed.
```jldoctest
julia> a = Dict("foo" => 0.0, "bar" => 42.0)
Dict{String, Float64} with 2 entries:
"bar" => 42.0
"foo" => 0.0
"bar" => 42.0

julia> b = Dict("baz" => 17, "bar" => 4711)
Dict{String, Int64} with 2 entries:
"bar" => 4711
"baz" => 17
"bar" => 4711

julia> merge(a, b)
Dict{String, Float64} with 3 entries:
"foo" => 0.0
"bar" => 4711.0
"baz" => 17.0
"foo" => 0.0

julia> merge(b, a)
Dict{String, Float64} with 3 entries:
"bar" => 42.0
"baz" => 17.0
"bar" => 42.0
"foo" => 0.0
```
"""
Expand Down Expand Up @@ -327,19 +327,19 @@ Method `merge(combine::Union{Function,Type}, args...)` as an alias of
```jldoctest
julia> a = Dict("foo" => 0.0, "bar" => 42.0)
Dict{String, Float64} with 2 entries:
"bar" => 42.0
"foo" => 0.0
"bar" => 42.0

julia> b = Dict("baz" => 17, "bar" => 4711)
Dict{String, Int64} with 2 entries:
"bar" => 4711
"baz" => 17
"bar" => 4711

julia> mergewith(+, a, b)
Dict{String, Float64} with 3 entries:
"foo" => 0.0
"bar" => 4753.0
"baz" => 17.0
"foo" => 0.0

julia> ans == mergewith(+)(a, b)
true
Expand Down Expand Up @@ -371,14 +371,14 @@ The function `f` is passed `key=>value` pairs.
```jldoctest
julia> d = Dict(1=>"a", 2=>"b", 3=>"c")
Dict{Int64, String} with 3 entries:
1 => "a"
2 => "b"
3 => "c"
1 => "a"

julia> filter!(p->isodd(p.first), d)
Dict{Int64, String} with 2 entries:
3 => "c"
1 => "a"
3 => "c"
```
"""
function filter!(f, d::AbstractDict)
Expand Down Expand Up @@ -413,8 +413,8 @@ The function `f` is passed `key=>value` pairs.
```jldoctest
julia> d = Dict(1=>"a", 2=>"b")
Dict{Int64, String} with 2 entries:
2 => "b"
1 => "a"
2 => "b"

julia> filter(p->isodd(p.first), d)
Dict{Int64, String} with 1 entry:
Expand Down
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,8 @@ Retrieve the value(s) stored at the given key or index within a collection. The
```jldoctest
julia> A = Dict("a" => 1, "b" => 2)
Dict{String, Int64} with 2 entries:
"b" => 2
"a" => 1
"b" => 2

julia> getindex(A, "a")
1
Expand Down
Loading