Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/defaultdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ for (DefaultDict,O) in [(:DefaultDict, :Unordered), (:DefaultOrderedDict, :Order
@delegate $DefaultDict.d [ sizehint, empty!, setindex!,
getindex, get, get!, haskey,
getkey, pop!, delete!, start, next,
done, next, isempty, length ]
done, isempty, length ]

similar{K,V,F}(d::$DefaultDict{K,V,F}) = $DefaultDict{K,V,F}(d.d.default)
in{T<:$DefaultDict}(key, v::Base.KeyIterator{T}) = key in keys(v.dict.d.d)
Expand Down Expand Up @@ -179,7 +179,7 @@ end
# @delegate DefaultSortedDict.d [ sizehint, empty!, setindex!,
# getindex, get, get!, haskey,
# getkey, pop!, delete!, start, next,
# done, next, isempty, length]
# done, isempty, length]

# similar{K,V,F}(d::DefaultSortedDict{K,V,F}) = DefaultSortedDict{K,V,F}(d.d.default)
# in{T<:DefaultSortedDict}(key, v::Base.KeyIterator{T}) = key in keys(v.dict.d.d)
13 changes: 11 additions & 2 deletions src/hashdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,19 @@ end

start(t::HashDict) = skip_deleted(t, 1)
done(t::HashDict, i) = done(t.vals, i)
next(t::HashDict, i) = ((t.keys[i],t.vals[i]), skip_deleted(t,i+1))
if VERSION >= v"0.4.0-dev+980"
next(t::HashDict, i) = (Pair(t.keys[i],t.vals[i]), skip_deleted(t,i+1))
else
next(t::HashDict, i) = ((t.keys[i],t.vals[i]), skip_deleted(t,i+1))
end


done{K,V}(t::HashDict{K,V,Ordered}, i) = done(t.order, i)
next{K,V}(t::HashDict{K,V,Ordered}, i) = ((t.keys[t.order[i]],t.vals[t.order[i]]), skip_deleted(t,i+1))
if VERSION >= v"0.4.0-dev+980"
next{K,V}(t::HashDict{K,V,Ordered}, i) = (Pair(t.keys[t.order[i]],t.vals[t.order[i]]), skip_deleted(t,i+1))
else
next{K,V}(t::HashDict{K,V,Ordered}, i) = ((t.keys[t.order[i]],t.vals[t.order[i]]), skip_deleted(t,i+1))
end
Copy link
Member

Choose a reason for hiding this comment

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

Base didn't actually start returning Pairs until pretty recently, even though the change to using Pairs everywhere else happened at v"0.4.0-dev+980".

This is probably okay, though--I doubt people are depending on this, and I doubt this would break code even if they were.

(Comments to the contrary welcome.)


isempty(t::HashDict) = (t.count == 0)
length(t::HashDict) = t.count
Expand Down
24 changes: 19 additions & 5 deletions test/test_ordereddict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ end

@test collect(keys(d)) == collect('b':'z')
@test collect(values(d)) == collect(2:26)
@test collect(d) == [(a,i) for (a,i) in zip('b':'z', 2:26)]
if VERSION >= v"0.4.0-dev+980"
@test collect(d) == [Pair(a,i) for (a,i) in zip('b':'z', 2:26)]
else
@test collect(d) == [(a,i) for (a,i) in zip('b':'z', 2:26)]
end

# Test for #60

Expand All @@ -63,11 +67,16 @@ od60[14]=15
# Copied and modified from Base/test/dict.jl

# OrderedDict
h = OrderedDict()
h = OrderedDict{Int,Int}()
for i=1:10000
h[i] = i+1
end
@test collect(h) == collect(zip(1:10000, 2:10001))

if VERSION >= v"0.4.0-dev+980"
@test collect(h) == [Pair(x,y) for (x,y) in zip(1:10000, 2:10001)]
else
@test collect(h) == collect(zip(1:10000, 2:10001))
end

for i=1:2:10000
delete!(h, i)
Expand Down Expand Up @@ -175,7 +184,12 @@ end

# TODO: this is a BoundsError on v0.3, ArgumentError on v0.4
#@test_throws ArgumentError first(OrderedDict())
@test first(OrderedDict([(:f, 2)])) == (:f,2)

if VERSION >= v"0.4.0-dev+980"
@test first(OrderedDict([(:f, 2)])) == Pair(:f,2)
else
@test first(OrderedDict([(:f, 2)])) == (:f,2)
end

# issue #1821
let
Expand Down Expand Up @@ -206,7 +220,7 @@ end
data_in = [ (rand(1:1000), randstring(2)) for _ in 1:1001 ]

# Populate the first dict
d1 = OrderedDict{Int, AbstractString}()
d1 = OrderedDict{Int, ASCIIString}()
for (k,v) in data_in
d1[k] = v
end
Expand Down