Skip to content

Add isless, isequal, hash for ChemicalSpecies#148

Merged
mfherbst merged 4 commits into
masterfrom
chemspecies-ordering
Jul 3, 2026
Merged

Add isless, isequal, hash for ChemicalSpecies#148
mfherbst merged 4 commits into
masterfrom
chemspecies-ordering

Conversation

@cortner

@cortner cortner commented Jul 1, 2026

Copy link
Copy Markdown
Member

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

cortner and others added 2 commits July 1, 2026 05:00
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>
@cortner cortner requested review from mfherbst and rkurchin July 1, 2026 12:23
@tjjarvinen

Copy link
Copy Markdown
Collaborator

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 == now, so that we could have == and isequal to be the same. But that would be a breaking release.

@cortner

cortner commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

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.

cortner and others added 2 commits July 1, 2026 06:34
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>
@cortner

cortner commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

Based on @tjjarvinen 's comments I assume this is ok and will merge tomorrow unless I hear from somebody blocking it.

@mfherbst mfherbst merged commit 3647049 into master Jul 3, 2026
9 checks passed
@mfherbst mfherbst deleted the chemspecies-ordering branch July 3, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants