Skip to content

Commit

Permalink
fix: add missing hash methods (#1719)
Browse files Browse the repository at this point in the history
Co-authored-by: Lars Göttgens <[email protected]>
  • Loading branch information
thofma and lgoettgens authored Jan 9, 2025
1 parent 039acfa commit e16ff76
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/GenOrd/FractionalIdeal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/GrpAb/Map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/Misc/OrdLocalization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/RCF/class_fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

###############################################################################
#
Expand Down
11 changes: 11 additions & 0 deletions test/GenOrd/Ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions test/GrpAb/Map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion test/Misc/OrdLocalization.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Qx,x = QQ["x"]
K,a = number_field(x^6+108)
OK = ring_of_integers(K)
Expand Down Expand Up @@ -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
13 changes: 13 additions & 0 deletions test/RCF/rcf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e16ff76

Please sign in to comment.