diff --git a/Project.toml b/Project.toml index d049bd4..8d10b38 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "OrderedCollections" uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.3.3" +version = "1.4.0" [compat] julia = "0.7, 1" diff --git a/src/OrderedCollections.jl b/src/OrderedCollections.jl index fbd691f..47e1128 100644 --- a/src/OrderedCollections.jl +++ b/src/OrderedCollections.jl @@ -3,7 +3,7 @@ module OrderedCollections import Base: <, <=, ==, convert, length, isempty, iterate, delete!, show, dump, empty!, getindex, setindex!, get, get!, in, haskey, keys, merge, copy, cat, - push!, pop!, insert!, + push!, pop!, popfirst!, insert!, union!, delete!, empty, sizehint!, isequal, hash, map, map!, reverse, diff --git a/src/ordered_dict.jl b/src/ordered_dict.jl index 73d9fc8..c5228a5 100644 --- a/src/ordered_dict.jl +++ b/src/ordered_dict.jl @@ -411,6 +411,13 @@ function pop!(h::OrderedDict) return key => _pop!(h, index) end +function popfirst!(h::OrderedDict) + h.ndel > 0 && rehash!(h) + key = h.keys[1] + index = ht_keyindex(h, key, false) + key => _pop!(h, index) +end + function pop!(h::OrderedDict, key) index = ht_keyindex(h, key, false) index > 0 ? _pop!(h, index) : throw(KeyError(key)) diff --git a/src/ordered_set.jl b/src/ordered_set.jl index 598fff4..3d3eada 100644 --- a/src/ordered_set.jl +++ b/src/ordered_set.jl @@ -47,6 +47,7 @@ function iterate(s::OrderedSet, i) end pop!(s::OrderedSet) = pop!(s.dict)[1] +popfirst!(s::OrderedSet) = popfirst!(s.dict)[1] diff --git a/test/test_ordered_dict.jl b/test/test_ordered_dict.jl index d664688..8f5fc6e 100644 --- a/test/test_ordered_dict.jl +++ b/test/test_ordered_dict.jl @@ -450,4 +450,11 @@ using OrderedCollections, Test @test od[14] == 14 end + @testset "ordered access" begin + od = OrderedDict(:a=>1, :b=>2, :c=>3) + @test popfirst!(od) == (:a => 1) + @test :a ∉ keys(od) + @test pop!(od) == (:c => 3) + @test :c ∉ keys(od) + end end # @testset OrderedDict