-
Notifications
You must be signed in to change notification settings - Fork 631
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
Do not add duplicate presentation contexts #1596
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## development #1596 +/- ##
===============================================
- Coverage 79.83% 79.80% -0.04%
===============================================
Files 273 274 +1
Lines 25053 25143 +90
===============================================
+ Hits 20002 20066 +64
- Misses 5051 5077 +26
☔ View full report in Codecov by Sentry. |
This is a PR without an issue. So generally asked: what is the reason or issue for this change? maybe some other solution, like an extra method "RemoveDuplicatePresentationContexts", that the user can call and that then checks all the presentation contexts before sending the request? |
in case the idea of this PR would be, to solve the issue, that the maximum number of Presentation Contexts is exceeded but could be solved by reducing duplicate, then you could add a check before sending the AssocationRequest if the number is higher than the allowed. If this is true, then remove duplicates. |
Sorry if this was missing a bit of context! I'm going through all our custom changes in our fork and - if they are not specific to our case - share them here.
It's true that the worst case scenario now introduces a O(n²) algorithm, but this worst case scenario only occurs if it is always the same SOP Class UID with different transfer syntaxes. In reality, what we tend to see, is that the number of presentation contexts in an association and the number of transfer syntaxes per presentation context is quite limited. (<100 presentation contexts and < 5 transfer syntaxes per context). Anyway, if you believe this feature is not worth the runtime cost, we can also always reject it. I personally don't see a lot of value in a dedicated |
To address your performance concerns (which were valid, even though I still believe the real world impact would have been small), I have switched the implementation to a HashSet based one. We now keep a hash set of existing presentation contexts, and only add a new presentation context if there is no collision with the hash set. Instead of a n^2 loop when adding a new presentation context, we now calculate the hash code of this presentation context and look it up in the hashset, which should be a O(1) operation. |
@@ -96,7 +104,11 @@ public void Add(DicomUID abstractSyntax, bool? userRole, bool? providerRole, par | |||
/// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.</exception> | |||
public void Add(DicomPresentationContext item) | |||
{ | |||
_pc.Add(item.ID, item); | |||
// Double-check against duplicate presentation contexts | |||
if (_uniquePcs.Add(item)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other possibility would be to remove an existing PC and add it to the end, which would change the order - but I think this is not something the user would think about, so it is most probably ok as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user wants to add it at the end, he can always the existing one first. I think the current implementation makes the most sense now..
Checklist
Changes proposed in this pull request: