Skip to content

Commit

Permalink
Merge pull request #76 from ExpandingMan/popfirst
Browse files Browse the repository at this point in the history
added popfirst! method
  • Loading branch information
oxinabox authored Feb 15, 2021
2 parents 2f4acde + e6b2d34 commit 844098f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/OrderedCollections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/ordered_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/ordered_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function iterate(s::OrderedSet, i)
end

pop!(s::OrderedSet) = pop!(s.dict)[1]
popfirst!(s::OrderedSet) = popfirst!(s.dict)[1]



Expand Down
7 changes: 7 additions & 0 deletions test/test_ordered_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 comments on commit 844098f

@oxinabox
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/30096

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.4.0 -m "<description of version>" 844098f75f13375642b9d2bf4efdf08c691403a7
git push origin v1.4.0

Please sign in to comment.