Skip to content

Decimal not usable as Dict key: no hash method defined #35

@Jasha10

Description

@Jasha10

Perhaps the hash could be defined in terms of the has of the underlying fields s, c and q of the Decimal struct. For reference, here is a stacktrace:

julia> d = Dict()
Dict{Any,Any} with 0 entries

julia> d[Decimal(123)] = 456
ERROR: MethodError: no method matching decompose(::Decimal)
Closest candidates are:
  decompose(::BigFloat) at hashing2.jl:133
  decompose(::Float64) at hashing2.jl:122
  decompose(::Float32) at hashing2.jl:111
  ...
Stacktrace:
 [1] hash(::Decimal, ::UInt64) at ./hashing2.jl:32
 [2] hash(::Decimal) at ./hashing.jl:18
 [3] hashindex(::Decimal, ::Int64) at ./dict.jl:169
 [4] ht_keyindex2!(::Dict{Any,Any}, ::Decimal) at ./dict.jl:309
 [5] setindex!(::Dict{Any,Any}, ::Int64, ::Decimal) at ./dict.jl:382
 [6] top-level scope at none:0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions