Define hash for PointSpace and DiracSpace - #698
Open
jishnub wants to merge 1 commit into
Open
Conversation
Space defines == (Space.jl:165) as spacescompatible && equal domains, but
no matching hash, so these spaces fell back to the identity-based default.
Two equal-valued spaces therefore hashed differently and could not be used
as Set elements or Dict keys:
julia> PointSpace(1:2) == PointSpace(1:2)
true
julia> hash(PointSpace(1:2)) == hash(PointSpace(1:2))
false
For both types spacescompatible reduces to comparing the sorted points, and
domain is derived from the same field, so hashing the points reproduces ==
exactly. The type is mixed in so PointSpace and DiracSpace with equal points
do not collide, matching == which is only defined within each type.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DZeBMyvW7qYiDfC7Tkb1vT
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #698 +/- ##
==========================================
- Coverage 75.20% 74.10% -1.11%
==========================================
Files 79 81 +2
Lines 8445 8603 +158
==========================================
+ Hits 6351 6375 +24
- Misses 2094 2228 +134 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spacedefines==generically insrc/Space.jl:165:but there is no matching
hash, so spaces fall back to the identity-based default. Two equal-valuedPointSpaces hash differently, which silently breaksSetandDict:For
PointSpaceandDiracSpace,spacescompatiblereduces to comparing the sortedpoints, anddomainis derived from that same field, so hashing the points reproduces==exactly. The type is mixed into the hash soPointSpace(1:2)andDiracSpace(1:2)don't collide — they are not==, sincespacescompatibleis only defined within each type.Note
==compares points numerically, soPointSpace([1,2]) == PointSpace([1.0,2.0]); the hash agrees, since Julia hashes numerically-equal numbers identically. Covered in the tests.Scope
This fixes only the two types where the failure is demonstrated. Every other
Spacesubtype still hashes by identity —==is generic buthashis not. A generichash(::Space, ::UInt)can't be derived safely, becausespacescompatibleis an arbitrary user-overridable predicate and nothing constrains which fields it consults. Fixing the rest means ahashalongside eachspacescompatible, which seems worth a separate issue rather than bundling here.Full test suite passes locally (219 passed, 1 pre-existing broken, 0 failures).
🤖 Generated with Claude Code
https://claude.ai/code/session_01DZeBMyvW7qYiDfC7Tkb1vT