Skip to content

Commit 42b9934

Browse files
ThomasBreuerfieker
authored andcommitted
Equal FPModules must have the same hash value (#2139)
There is a `==` method for two `FPModule`s that compares w.r.t. equality as sets. The default `hash` method compares the `objectid`s. In order to satisfy the general rule that `isequal(x,y)` implies `hash(x) == hash(y)`, we need a special `hash` method.
1 parent d3d8388 commit 42b9934

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Module.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ function ==(M::FPModule{T}, N::FPModule{T}) where T <: RingElement
254254
return true
255255
end
256256

257+
# Equal `FPModule`s must have the same `hash` value.
258+
Base.hash(M::FPModule, h::UInt) = h # FIXME
259+
257260
###############################################################################
258261
#
259262
# Isomorphism

test/generic/Module-test.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ end
1919
test_rand(F, 1:9)
2020
end
2121

22+
@testset "Generic.Module.hash" begin
23+
# equal objects in the sense of `isequal` must have the same `hash` values
24+
F = free_module(QQ, 2)
25+
M1 = sub(F, [])[1]
26+
M2 = sub(F, [])[1]
27+
@test objectid(M1) != objectid(M2)
28+
@test isequal(M1, M2)
29+
@test hash(M1) == hash(M2)
30+
end
31+
2232
@testset "Generic.Module.manipulation" begin
2333
for R in [ZZ, QQ]
2434
for iter = 1:100

0 commit comments

Comments
 (0)