Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement equality for Element #92

Merged
merged 2 commits into from
Jan 24, 2023
Merged

Implement equality for Element #92

merged 2 commits into from
Jan 24, 2023

Conversation

martinholters
Copy link
Member

This implements == (and consistent hash) for Element.

julia> resistor(1000) == resistor(1000)
false         # before
true          # this PR

It's still the case that resistor(1000) !== resistor(1000), but that should be seen as an implementation detail that might change in the future.

To be consistent, it is now possibly to add the same Element instance for than once to the same Circuit:

julia> R = resistor(1000); circ = Circuit();

julia> add!(circ, R)
Symbol("##296")

julia> add!(circ, R)
Symbol("##296")    # before
Symbol("##297")    # this PR

julia> ACME.nb(circ)
1                  # before
2                  # this PR

Note the following change:

Before:
```julia
julia> R = resistor(1000); circ = Circuit();

julia> add!(circ, R)
Symbol("##296")

julia> add!(circ, R)
Symbol("##296")

julia> ACME.nb(circ)
1
```
After:
```julia
julia> R = resistor(1000); circ = Circuit();

julia> add!(circ, R)
Symbol("##296")

julia> add!(circ, R)
Symbol("##297")

julia> ACME.nb(circ)
2
```
I.e. the same element can now be added twice. In general, element
instances should not have an identity, so the new behaviour seems more
reasonable. (The same `R` could already be added to another circuit
without having any effect on its presence in the first one, for
example.)
So that e.g. `resistor(1000) == resistor(1000)`, which previously gave
`false`.
@martinholters martinholters merged commit 6fda63a into main Jan 24, 2023
@martinholters martinholters deleted the mh/element-equality branch January 24, 2023 08:40
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.

1 participant