From e16ff766ffe73b4d8507b8b904fdfb4908142c42 Mon Sep 17 00:00:00 2001 From: Tommy Hofmann Date: Thu, 9 Jan 2025 20:46:52 +0100 Subject: [PATCH] fix: add missing hash methods (#1719) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lars Göttgens --- src/GenOrd/FractionalIdeal.jl | 4 ++++ src/GrpAb/Map.jl | 2 ++ src/Misc/OrdLocalization.jl | 7 +++++++ src/RCF/class_fields.jl | 3 +++ test/GenOrd/Ideal.jl | 11 +++++++++++ test/GrpAb/Map.jl | 8 ++++++++ test/Misc/OrdLocalization.jl | 12 +++++++++++- test/RCF/rcf.jl | 13 +++++++++++++ 8 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/GenOrd/FractionalIdeal.jl b/src/GenOrd/FractionalIdeal.jl index 8cfeb29515..f74b87f38f 100644 --- a/src/GenOrd/FractionalIdeal.jl +++ b/src/GenOrd/FractionalIdeal.jl @@ -276,6 +276,10 @@ function ==(A::GenOrdFracIdl, B::GenOrdFracIdl) return isone(denominator(C, copy = false)) && isone(norm(C)) end +function Base.hash(A::GenOrdFracIdl, h::UInt) + return hash(order(A), hash(basis_matrix(A), h)) +end + ################################################################################ # # Colon diff --git a/src/GrpAb/Map.jl b/src/GrpAb/Map.jl index 0aa78dde3b..c5d9368411 100644 --- a/src/GrpAb/Map.jl +++ b/src/GrpAb/Map.jl @@ -216,6 +216,8 @@ end ==(f::FinGenAbGroupHom, g::FinGenAbGroupHom) = domain(f) === domain(g) && codomain(f) === codomain(g) && all(x -> f(x) == g(x), gens(domain(f))) +Base.hash(f::FinGenAbGroupHom, h::UInt) = h + ################################################################################ # # Inverse of a map diff --git a/src/Misc/OrdLocalization.jl b/src/Misc/OrdLocalization.jl index 70b693317c..cce4832eb8 100644 --- a/src/Misc/OrdLocalization.jl +++ b/src/Misc/OrdLocalization.jl @@ -208,6 +208,13 @@ function ==(a::OrdLocElem{T}, b::OrdLocElem{T}) where {T <: AbsSimpleNumFieldEle return data(a) == data(b) end +function Base.hash(a::OrdLocElem, h::UInt) + b = 0x33dd41cd510034d2%UInt + b = xor(hash(parent(a), h), b) + b = xor(hash(data(a), h), b) + return b +end + ############################################################################## # # Inversion diff --git a/src/RCF/class_fields.jl b/src/RCF/class_fields.jl index 9852b165ff..23a4c1763d 100644 --- a/src/RCF/class_fields.jl +++ b/src/RCF/class_fields.jl @@ -254,6 +254,9 @@ function ==(a::ClassField, b::ClassField) return is_eq(kernel(h[2])[1], kernel(h[1])[1]) end +function Base.hash(a::ClassField, h::UInt) + return hash(base_ring(a), h) +end ############################################################################### # diff --git a/test/GenOrd/Ideal.jl b/test/GenOrd/Ideal.jl index 37dded3327..441f0c1bdc 100644 --- a/test/GenOrd/Ideal.jl +++ b/test/GenOrd/Ideal.jl @@ -77,3 +77,14 @@ end end end + +let + # hashing of fractional ideals + k = GF(7) + kx, x = rational_function_field(k, "x") + kt = parent(numerator(x)) + ky, y = polynomial_ring(kx, "y") + F, a = function_field(y^2+x) + O = integral_closure(kt, F) + @test hash(fractional_ideal(a*O)) == hash(fractional_ideal(a*O)) +end diff --git a/test/GrpAb/Map.jl b/test/GrpAb/Map.jl index 9149fd4d52..55a993ca04 100644 --- a/test/GrpAb/Map.jl +++ b/test/GrpAb/Map.jl @@ -124,4 +124,12 @@ @test_throws ArgumentError preinverse(f) @test_throws ArgumentError postinverse(g) end + + let + G = abelian_group([2, 2]) + h = zero_map(G, G); + hh = zero_map(G, G); + @test h == hh + @test hash(h) == hash(hh) + end end diff --git a/test/Misc/OrdLocalization.jl b/test/Misc/OrdLocalization.jl index 9e23aa2a94..5e5a15fda8 100644 --- a/test/Misc/OrdLocalization.jl +++ b/test/Misc/OrdLocalization.jl @@ -1,4 +1,3 @@ - Qx,x = QQ["x"] K,a = number_field(x^6+108) OK = ring_of_integers(K) @@ -124,4 +123,15 @@ end @test isone(L(13//13)) == true @test is_unit(L(50//2)) == false end + + let + # hashing + Qx, x = QQ["x"] + K, a = number_field(x^6 + 108) + OK = ring_of_integers(K) + lp = prime_decomposition(OK, 5) + P = lp[1][1] + L = localization(OK, P) + @test hash(one(L)) == hash(one(L)) + end end diff --git a/test/RCF/rcf.jl b/test/RCF/rcf.jl index 3eec91112b..02103ead7a 100644 --- a/test/RCF/rcf.jl +++ b/test/RCF/rcf.jl @@ -380,3 +380,16 @@ let L, = number_field(x^3 - 840539241479//13824*a^5 - 18036715089631//9216*a^4 - 18036715089631//9216*a^3 - 840539241479//13824*a^2 - 7320065966297//9216) @test !is_abelian(L) end + +let + # fix hashing + K, = quadratic_field(-1) + OK = maximal_order(K) + C = ray_class_field(1*OK) + CC = ray_class_field(1*OK) + @test C == CC + @test hash(C) == hash(CC) + D = Dict() + D[C] = 1 + @test haskey(D, CC) +end