Add isless, isequal, hash for ChemicalSpecies#148
Conversation
Impose a strict total order + identity on the raw fields (atomic_number, n_neutrons, name), enabling sort and correct use in Set/Dict/unique. These are deliberately stricter than the wildcard `==` matching relation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
This is a needed addition and a good implementation! There is a one issue that this raises and that is the case of h = ChemicalSpecies(:H)
d = ChemicalSpecies(:D)
h == d # true
isequal(h, d) # false
# meaning `==` is not same as `isequal`This is completely valid in Julia, but can cause some issues, if you don't know it before hand. So, it might be a good to add a note to the documentation that this exist. We could even discuss on whether we should have a dedicated name for a function that does the current version of |
|
Fair point. Since making == and isequal behave the same is breaking I would document this, merge and then file an issue for the breaking change that you suggest. |
Explain in both the docstring and the utilities docs page that == is a wildcard matching relation (non-transitive), while isequal/hash/isless provide strict identity/ordering used by sort, Set, Dict, unique. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Based on @tjjarvinen 's comments I assume this is ok and will merge tomorrow unless I hear from somebody blocking it. |
Implementation of isless, isequal, hash for ChemicalSpecies. Original need for me was sorting, but then it became apparent that these are three canonical related things that are important for: sort, Dict, Set and similar.
Simple addition. Non-breaking.
🤖 Generated with Claude Code