Skip to content

Commit

Permalink
Add many hash functions (#1695)
Browse files Browse the repository at this point in the history
* Add `hash(::Divisor)`

* Add `hash(::EllipticCurve)`

* Add `hash(::FunFldDiff)`

* Fix `==(::KodairaSymbol,::KodairaSymbol)`; add hash

* Add `hash` for `Line` and `Polygon`

* Add `hash(::RelSimpleNumFieldEmbedding)`

* Add `hash(::QuadBin)`

* Add `hash(::AbsSimpleNumFieldEmbedding)`

* Add `hash(::AbsNumFieldOrderSet)`

* Add `hash(::AbsNumFieldOrder)`

* Add `hash(::QmodnZ)`

* Add `hash(::Union{ZZIdl, ZZFracIdl})`

* Add `hash(::EllCrvIso)`
  • Loading branch information
lgoettgens authored Nov 29, 2024
1 parent 5d2ba17 commit a9f1690
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 4 deletions.
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 @@ end
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
end

function Base.hash(K::KodairaSymbol, h::UInt)
return hash(K.ksymbol, h)
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 @@ function Base.:(==)(df::FunFldDiff, dg::FunFldDiff)
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
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 @@ end
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)

################################################################################
#
# 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 @@ function Base.:(==)(a::QmodnZ, b::QmodnZ)
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
end

function Base.:(==)(a::QmodnZElem, b::QmodnZElem)
if parent(a).trivialmodulus
return is_integral(a.elt - b.elt)
Expand All @@ -158,7 +164,7 @@ function Base.hash(a::QmodnZElem, h::UInt)
if parent(a).trivialmodulus
return hash(a.elt, h)
end
error("not implemented")
return h
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 @@ struct ZZFracIdl <: NumFieldOrderFractionalIdeal
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 @@ function ==(I::ZZIdl, J::ZZIdl)
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)
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 @@ function Base.:(==)(L::Line, L2::Line)
return L.points == L2.points
end

function Base.hash(L::Line, h::UInt)
return hash(L.points, h)
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)
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 @@ function ==(R::AbsNumFieldOrder, S::AbsNumFieldOrder)
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 @@ function ==(R::AbsNumFieldOrderSet, S::AbsNumFieldOrderSet)
return R.nf === S.nf
end

function Base.hash(R::AbsNumFieldOrderSet, h::UInt)
return hash(R.nf, h)
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 @@ function ==(f1::QuadBin, f2::QuadBin)
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
end

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

0 comments on commit a9f1690

Please sign in to comment.