From 761d35c4884fbb844ad82561d7df9c2a60af33d5 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Tue, 21 Nov 2023 01:19:36 +0100 Subject: [PATCH 1/3] rm deprecations, bump version --- Project.toml | 2 +- README.md | 2 ++ src/OrderedCollections.jl | 3 --- src/dict_sorting.jl | 3 --- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index 9a258dd..17f753a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "OrderedCollections" uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.6.2" +version = "2.0.0" [compat] julia = "1.6" diff --git a/README.md b/README.md index e04baf3..8b14fa0 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ OrderedCollections.jl ===================== +Note: v2.0 removes deprecations present in v1.6.2 (for `sort!(::Dict)` and `similar(::Union{OrderedDict, OrderedSet})`), but is otherwise identical. + This package implements OrderedDicts and OrderedSets, which are similar to containers in base Julia. However, during iteration the Ordered* containers return items in the order in which they were added to the collection. It also implements `LittleDict` which is a ordered dictionary, that is much faster than any other `AbstractDict` (ordered or not) for small collections. diff --git a/src/OrderedCollections.jl b/src/OrderedCollections.jl index 47e1128..5628114 100644 --- a/src/OrderedCollections.jl +++ b/src/OrderedCollections.jl @@ -26,7 +26,4 @@ module OrderedCollections include("ordered_set.jl") include("dict_sorting.jl") - import Base: similar - @deprecate similar(d::OrderedDict) empty(d) - @deprecate similar(s::OrderedSet) empty(s) end diff --git a/src/dict_sorting.jl b/src/dict_sorting.jl index c4ef1c9..32e1e3c 100644 --- a/src/dict_sorting.jl +++ b/src/dict_sorting.jl @@ -33,8 +33,6 @@ end sort(d::Union{OrderedDict,OrderedSet}; args...) = sort!(copy(d); args...) -@deprecate sort(d::Dict; args...) sort!(OrderedDict(d); args...) - function sort(d::LittleDict; byvalue::Bool=false, args...) if byvalue p = sortperm(d.vals; args...) @@ -43,4 +41,3 @@ function sort(d::LittleDict; byvalue::Bool=false, args...) end return LittleDict(d.keys[p], d.vals[p]) end - From a20bd7628fa9dd8dcf1da161085e9c284dab3398 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Tue, 21 Nov 2023 01:27:06 +0100 Subject: [PATCH 2/3] remove more depwarns --- README.md | 2 +- src/ordered_dict.jl | 2 +- src/ordered_set.jl | 26 -------------------------- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 8b14fa0..ed2f314 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ OrderedCollections.jl ===================== -Note: v2.0 removes deprecations present in v1.6.2 (for `sort!(::Dict)` and `similar(::Union{OrderedDict, OrderedSet})`), but is otherwise identical. +Note: v2.0 removes deprecations present in v1.6.2 (for `sort!(::Dict)`, `similar(::Union{OrderedDict, OrderedSet})`, indexing, and `convert` from non-ordered types), but is otherwise identical. This package implements OrderedDicts and OrderedSets, which are similar to containers in base Julia. However, during iteration the Ordered* containers return items in the order in which they were added to the collection. diff --git a/src/ordered_dict.jl b/src/ordered_dict.jl index 28945fe..11cacf5 100644 --- a/src/ordered_dict.jl +++ b/src/ordered_dict.jl @@ -100,7 +100,7 @@ isordered(::Type{T}) where {T<:OrderedDict} = true function convert(::Type{OrderedDict{K,V}}, d::AbstractDict) where {K,V} d isa OrderedDict{K, V} && return d if !isordered(typeof(d)) - Base.depwarn("Conversion to OrderedDict is deprecated for unordered associative containers (in this case, $(typeof(d))). Use an ordered or sorted associative type, such as SortedDict and OrderedDict.", :convert) + error("Conversion to OrderedDict is not supported for unordered associative containers (in this case, $(typeof(d))). Use an ordered or sorted associative type, such as SortedDict and OrderedDict.", :convert) end h = OrderedDict{K,V}() for (k,v) in d diff --git a/src/ordered_set.jl b/src/ordered_set.jl index b7f329a..786aacd 100644 --- a/src/ordered_set.jl +++ b/src/ordered_set.jl @@ -79,29 +79,3 @@ function hash(s::OrderedSet, h::UInt) hash(s.dict.keys, h) end - -# Deprecated functionality, see -# https://github.com/JuliaCollections/DataStructures.jl/pull/180#issuecomment-400269803 - -function getindex(s::OrderedSet, i::Int) - Base.depwarn("indexing is deprecated for OrderedSet, please rewrite your code to use iteration", :getindex) - s.dict.ndel > 0 && rehash!(s.dict) - return s.dict.keys[i] -end - -function lastindex(s::OrderedSet) - Base.depwarn("indexing is deprecated for OrderedSet, please rewrite your code to use iteration", :lastindex) - s.dict.ndel > 0 && rehash!(s.dict) - return lastindex(s.dict.keys) -end - -function nextind(::OrderedSet, i::Int) - Base.depwarn("indexing is deprecated for OrderedSet, please rewrite your code to use iteration", :lastindex) - return i + 1 # Needed on 0.7 to mimic array indexing. -end - -function keys(s::OrderedSet) - Base.depwarn("indexing is deprecated for OrderedSet, please rewrite your code to use iteration", :lastindex) - s.dict.ndel > 0 && rehash!(s.dict) - return 1:length(s) -end From 5b5906493ffdc952e895e63571ac9a6805462b56 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Tue, 21 Nov 2023 01:34:32 +0100 Subject: [PATCH 3/3] rm convert method --- README.md | 5 ++++- src/ordered_dict.jl | 18 ------------------ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index ed2f314..6940d9b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,10 @@ OrderedCollections.jl ===================== -Note: v2.0 removes deprecations present in v1.6.2 (for `sort!(::Dict)`, `similar(::Union{OrderedDict, OrderedSet})`, indexing, and `convert` from non-ordered types), but is otherwise identical. +**Changes in v2.0:** + +* removes deprecations present in v1.6.2 (for `sort!(::Dict)`, `similar(::Union{OrderedDict, OrderedSet})`, indexing, and `convert` from non-ordered types) +* removes `convert(::OrderedDict, ::AbstractDict)` method to reduce invalidations, instead falling back to Base's method, which uses the constructor. This results in copying keys and values. This package implements OrderedDicts and OrderedSets, which are similar to containers in base Julia. However, during iteration the Ordered* containers return items in the order in which they were added to the collection. diff --git a/src/ordered_dict.jl b/src/ordered_dict.jl index 11cacf5..03c4ad4 100644 --- a/src/ordered_dict.jl +++ b/src/ordered_dict.jl @@ -96,24 +96,6 @@ defined order (such as `OrderedDict` and `SortedDict`), and `false` otherwise. isordered(::Type{T}) where {T<:AbstractDict} = false isordered(::Type{T}) where {T<:OrderedDict} = true -# conversion between OrderedDict types -function convert(::Type{OrderedDict{K,V}}, d::AbstractDict) where {K,V} - d isa OrderedDict{K, V} && return d - if !isordered(typeof(d)) - error("Conversion to OrderedDict is not supported for unordered associative containers (in this case, $(typeof(d))). Use an ordered or sorted associative type, such as SortedDict and OrderedDict.", :convert) - end - h = OrderedDict{K,V}() - for (k,v) in d - ck = convert(K,k) - if !haskey(h,ck) - h[ck] = convert(V,v) - else - error("key collision during dictionary conversion") - end - end - return h -end - isslotempty(slot_value::Integer) = slot_value == 0 isslotfilled(slot_value::Integer) = slot_value > 0 isslotmissing(slot_value::Integer) = slot_value < 0