Skip to content

Commit 1b0b931

Browse files
committed
add hash method for Polys
1 parent 9ce8287 commit 1b0b931

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/Polynomials.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ function ==(p1::Poly, p2::Poly)
348348
end
349349
end
350350

351+
Base.hash(f::Poly, h::UInt) = hash(f.var, hash(f.a, h))
352+
351353
"""
352354
* `polyval(p::Poly, x::Number)`: Evaluate the polynomial `p` at `x` using Horner's method.
353355

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,7 @@ r = Poly([1.0, 2, 3])
246246
@test string_eval_poly(q, 5) == q(5)
247247
@test string_eval_poly(r, 5) == r(5)
248248

249+
## check hashing
250+
p = poly([1,2,3])
251+
q = poly([1,2,3])
252+
@test hash(p) == hash(q)

0 commit comments

Comments
 (0)