Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add many hash functions #1695

Merged
merged 13 commits into from
Nov 29, 2024
6 changes: 6 additions & 0 deletions src/EllCrv/EllCrv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ function ==(E::EllipticCurve, F::EllipticCurve)
return a_invariants(E) == a_invariants(F) && base_field(E) == base_field(F)
end

function Base.hash(E::EllipticCurve, h::UInt)
h = hash(a_invariants(E), h)
h = hash(base_field(E), h)
return h
end

################################################################################
#
# Elementary invariants
Expand Down
8 changes: 8 additions & 0 deletions src/EllCrv/Isomorphisms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,14 @@ function ==(f::EllCrvIso, g::EllCrvIso)
return f.data == g.data && Ef == Eg && base_field(Ef) == base_field(Eg)
end

function Base.hash(f::EllCrvIso, h::UInt)
Ef = domain(f)
h = hash(f.data, h)
h = hash(Ef, h)
h = hash(base_field(Ef), h)
return h
end


################################################################################
#
Expand Down
6 changes: 5 additions & 1 deletion src/EllCrv/LocalData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,11 @@
Return true if $K1$ and $K2$ are the same Kodaira symbol.
"""
function ==(K1::KodairaSymbol, K2::KodairaSymbol)
return K1.ksymbol == K2.kymbol
return K1.ksymbol == K2.ksymbol

Check warning on line 820 in src/EllCrv/LocalData.jl

View check run for this annotation

Codecov / codecov/patch

src/EllCrv/LocalData.jl#L820

Added line #L820 was not covered by tests
end

function Base.hash(K::KodairaSymbol, h::UInt)
return hash(K.ksymbol, h)

Check warning on line 824 in src/EllCrv/LocalData.jl

View check run for this annotation

Codecov / codecov/patch

src/EllCrv/LocalData.jl#L823-L824

Added lines #L823 - L824 were not covered by tests
end


Expand Down
6 changes: 6 additions & 0 deletions src/FunField/Differential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
return function_field(df) === function_field(df) && df.f == df.f
end

function Base.hash(df::FunFldDiff, h::UInt)
h = hash(function_field(df), h)
h = hash(df.f, h)
return h

Check warning on line 85 in src/FunField/Differential.jl

View check run for this annotation

Codecov / codecov/patch

src/FunField/Differential.jl#L82-L85

Added lines #L82 - L85 were not covered by tests
end

################################################################################
#
# Arithmetic
Expand Down
2 changes: 2 additions & 0 deletions src/FunField/Divisor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@
Base.:(==)(D1::Divisor, D2::Divisor) = ideals(D1) == ideals(D2)
Base.isequal(D1::Divisor, D2::Divisor) = a == b

Base.hash(D::Divisor, h::UInt) = hash(ideals(D), h)

Check warning on line 228 in src/FunField/Divisor.jl

View check run for this annotation

Codecov / codecov/patch

src/FunField/Divisor.jl#L228

Added line #L228 was not covered by tests

################################################################################
#
# Divisor arithmetic
Expand Down
8 changes: 7 additions & 1 deletion src/GrpAb/Dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@
return a.n == b.n && a.d == b.d
end

function Base.hash(a::QmodnZ, h::UInt)
h = hash(a.n, h)
h = hash(a.d, h)
return h

Check warning on line 150 in src/GrpAb/Dual.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/Dual.jl#L147-L150

Added lines #L147 - L150 were not covered by tests
end

function Base.:(==)(a::QmodnZElem, b::QmodnZElem)
if parent(a).trivialmodulus
return is_integral(a.elt - b.elt)
Expand All @@ -158,7 +164,7 @@
if parent(a).trivialmodulus
return hash(a.elt, h)
end
error("not implemented")
return h

Check warning on line 167 in src/GrpAb/Dual.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/Dual.jl#L167

Added line #L167 was not covered by tests
end

for T in [ZZRingElem, Integer, QQFieldElem, Rational]
Expand Down
6 changes: 6 additions & 0 deletions src/NumField/ComplexEmbeddings/NfAbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ function Base.:(==)(f::AbsSimpleNumFieldEmbedding, g::AbsSimpleNumFieldEmbedding
_absolute_index(f) == _absolute_index(g)
end

function Base.hash(f::AbsSimpleNumFieldEmbedding, h::UInt)
h = hash(number_field(f), h)
h = hash(_absolute_index(f), h)
return h
end

################################################################################
#
# String I/O
Expand Down
6 changes: 6 additions & 0 deletions src/NumField/ComplexEmbeddings/NfRel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ function Base.:(==)(f::RelSimpleNumFieldEmbedding, g::RelSimpleNumFieldEmbedding
_absolute_index(f) == _absolute_index(g)
end

function Base.hash(f::RelSimpleNumFieldEmbedding, h::UInt)
h = hash(number_field(f), h)
h = hash(_absolute_index(f), h)
return h
end

################################################################################
#
# Conjugate embedding
Expand Down
10 changes: 8 additions & 2 deletions src/NumField/QQ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
end
end

Base.hash(x::ZZIdl, h::UInt) = hash(gen(x), h)

order(::ZZIdl) = ZZ

order(::ZZFracIdl) = ZZ
Expand Down Expand Up @@ -93,10 +91,18 @@
return I.gen == J.gen
end

function Base.hash(I::ZZIdl, h::UInt)
return hash(I.gen, h)
end

function ==(I::ZZFracIdl, J::ZZFracIdl)
return I.gen == J.gen
end

function Base.hash(I::ZZFracIdl, h::UInt)
return hash(I.gen, h)

Check warning on line 103 in src/NumField/QQ.jl

View check run for this annotation

Codecov / codecov/patch

src/NumField/QQ.jl#L102-L103

Added lines #L102 - L103 were not covered by tests
end

# access
gen(I::ZZIdl) = I.gen

Expand Down
8 changes: 8 additions & 0 deletions src/NumFieldOrd/NfOrd/MaxOrd/Polygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,18 @@
return L.points == L2.points
end

function Base.hash(L::Line, h::UInt)
return hash(L.points, h)

Check warning on line 95 in src/NumFieldOrd/NfOrd/MaxOrd/Polygons.jl

View check run for this annotation

Codecov / codecov/patch

src/NumFieldOrd/NfOrd/MaxOrd/Polygons.jl#L94-L95

Added lines #L94 - L95 were not covered by tests
end

function Base.:(==)(P::Polygon, P2::Polygon)
return P.lines == P2.lines
end

function Base.hash(P::Polygon, h::UInt)
return hash(P.lines, h)

Check warning on line 103 in src/NumFieldOrd/NfOrd/MaxOrd/Polygons.jl

View check run for this annotation

Codecov / codecov/patch

src/NumFieldOrd/NfOrd/MaxOrd/Polygons.jl#L102-L103

Added lines #L102 - L103 were not covered by tests
end

###############################################################################
#
# Lower convex hull of a set of points
Expand Down
12 changes: 12 additions & 0 deletions src/NumFieldOrd/NfOrd/NfOrd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,14 @@
return hnf(R.basis_matrix) == hnf(S.basis_matrix)
end

function hash(R::AbsNumFieldOrder, h::UInt)
h = hash(nf(R), h)
h = hash(discriminant(R), h)
assure_has_basis_matrix(R)
h = hash(hnf(R.basis_matrix), h)
return h
end

@doc raw"""
is_contained(R::AbsNumFieldOrder, S::AbsNumFieldOrder) -> Bool

Expand All @@ -1152,6 +1160,10 @@
return R.nf === S.nf
end

function Base.hash(R::AbsNumFieldOrderSet, h::UInt)
return hash(R.nf, h)

Check warning on line 1164 in src/NumFieldOrd/NfOrd/NfOrd.jl

View check run for this annotation

Codecov / codecov/patch

src/NumFieldOrd/NfOrd/NfOrd.jl#L1163-L1164

Added lines #L1163 - L1164 were not covered by tests
end

################################################################################
#
# Trace matrix
Expand Down
8 changes: 8 additions & 0 deletions src/QuadForm/QuadBin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@
return f1[1] == f2[1] && f1[2] == f2[2] && f1[3] == f2[3]
end

function Base.hash(f::QuadBin, h::UInt)
h = hash(base_ring(f), h)
h = hash(f[1], h)
h = hash(f[2], h)
h = hash(f[3], h)
return h

Check warning on line 303 in src/QuadForm/QuadBin.jl

View check run for this annotation

Codecov / codecov/patch

src/QuadForm/QuadBin.jl#L298-L303

Added lines #L298 - L303 were not covered by tests
end

###############################################################################
#
# Arithmetic
Expand Down
Loading