From 441a5a91e6936d1b96f4330c054aa67570fd81bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 11 May 2023 16:28:10 +0200 Subject: [PATCH] Add `hash(::TropicalSemiringElem)` --- src/AlgebraicGeometry/TropicalGeometry/semiring.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/AlgebraicGeometry/TropicalGeometry/semiring.jl b/src/AlgebraicGeometry/TropicalGeometry/semiring.jl index 728c4f700ec3..07b53e609807 100644 --- a/src/AlgebraicGeometry/TropicalGeometry/semiring.jl +++ b/src/AlgebraicGeometry/TropicalGeometry/semiring.jl @@ -227,7 +227,7 @@ Oscar.isone(x::TropicalSemiringElem) = !isinf(x) && iszero(data(x)) ################################################################################ # -# Equality +# Equality and hash # ################################################################################ @@ -237,6 +237,15 @@ function Base.:(==)(x::TropicalSemiringElem, y::TropicalSemiringElem) return data(x) == data(y) end +function Base.hash(x::TropicalSemiringElem, h::UInt) + b = 0x4df38853cc07aa27 % UInt + h = hash(isinf(x), h) + if !isinf(x) + h = hash(data(x), h) + end + return xor(h, b) +end + ################################################################################ # # Comparison