Skip to content

Commit 07ee08e

Browse files
committed
added popfirst\! method
1 parent 2f4acde commit 07ee08e

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "OrderedCollections"
22
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
3-
version = "1.3.3"
3+
version = "1.3.4"
44

55
[compat]
66
julia = "0.7, 1"

src/OrderedCollections.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module OrderedCollections
33
import Base: <, <=, ==, convert, length, isempty, iterate, delete!,
44
show, dump, empty!, getindex, setindex!, get, get!,
55
in, haskey, keys, merge, copy, cat,
6-
push!, pop!, insert!,
6+
push!, pop!, popfirst!, insert!,
77
union!, delete!, empty, sizehint!,
88
isequal, hash,
99
map, map!, reverse,

src/ordered_dict.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,13 @@ function pop!(h::OrderedDict)
411411
return key => _pop!(h, index)
412412
end
413413

414+
function popfirst!(h::OrderedDict)
415+
h.ndel > 0 && rehash!(h)
416+
key = h.keys[1]
417+
index = ht_keyindex(h, key, false)
418+
key => _pop!(h, index)
419+
end
420+
414421
function pop!(h::OrderedDict, key)
415422
index = ht_keyindex(h, key, false)
416423
index > 0 ? _pop!(h, index) : throw(KeyError(key))

src/ordered_set.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function iterate(s::OrderedSet, i)
4747
end
4848

4949
pop!(s::OrderedSet) = pop!(s.dict)[1]
50+
popfirst!(s::OrderedSet) = popfirst!(s.dict)[1]
5051

5152

5253

test/test_ordered_dict.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,4 +450,11 @@ using OrderedCollections, Test
450450
@test od[14] == 14
451451
end
452452

453+
@testset "ordered access" begin
454+
od = OrderedDict(:a=>1, :b=>2, :c=>3)
455+
@test popfirst!(od) == (:a => 1)
456+
@test :a keys(od)
457+
@test pop!(od) == (:c => 3)
458+
@test :c keys(od)
459+
end
453460
end # @testset OrderedDict

0 commit comments

Comments
 (0)