Skip to content

Commit

Permalink
dict: generic keys() and values() functions for Associative.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed May 10, 2012
1 parent d607115 commit b021368
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 18 additions & 0 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ function show(io, t::Associative)
end
end

function keys(a::Associative)
i = 0
keyz = Array(Any,length(a))
for (k,v) in a
keyz[i+=1] = k
end
return keyz
end

function values(a::Associative)
i = 0
vals = Array(Any,length(a))
for (k,v) in a
vals[i+=1] = v
end
return vals
end

# some support functions

function _tablesz(i::Integer)
Expand Down
6 changes: 3 additions & 3 deletions test/hashing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ types = {
Rational{Int8}, Rational{Uint8}, Rational{Int16}, Rational{Uint16},
Rational{Int32}, Rational{Uint32}, Rational{Int64}, Rational{Uint64}
}
values = [
vals = [
typemin(Int64),
-integer(maxintfloat(Float64))+(-4:1),
typemin(Int32),
Expand All @@ -15,13 +15,13 @@ values = [
typemax(Int64),
]

for T=types, S=types, x=values
for T=types, S=types, x=vals
a = convert(T,x)
b = convert(S,x)
#println("$(typeof(a)) $a")
#println("$(typeof(b)) $b")
@assert !isequal(a,b) || hash(a)==hash(b)
# for y=values
# for y=vals
# println("T=$T; S=$S; x=$x; y=$y")
# c = convert(T,x//y)
# d = convert(S,x//y)
Expand Down

0 comments on commit b021368

Please sign in to comment.