-
Notifications
You must be signed in to change notification settings - Fork 271
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
SortedSet
invariants can be broken if Element
violates Comparable
requirements
#137
Comments
This implementation of When the requirements of |
I concur! We can't say anything about the order of items in a Sadly this is a case of garbage in, garbage out -- like is the case with As long as broken element types don't trigger invalid memory accesses or other undefined behavior in these data structures, the issue is entirely the fault of the broken type, not the data structure implementation. Ideally code that relies on protocol requirements (like There are probably ways to add similar opportunistic tests to these sorted data structures, too. Unfortunately, we actually have some types in the stdlib that intentionally violate |
SortedSet
incorrectly reports that the element is not present in the set.SortedSet
invariants can be broken if Element
violates Comparable
requirements
Thanks folks. I know see how my |
SortedSet
incorrectly reports that the element is not contained in it.Information
feature/SortedCollections
Checklist
Steps to Reproduce
The issue happens when two elements are "NOT EQUAL" when compared via "==" operator, but "<" always returns false for them.
Here's a sample code:
Expected behavior
set.contains
returns true for the element that was inserted.Actual behavior
set.contains
returns false for the element that was already inserted.The text was updated successfully, but these errors were encountered: