-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Sets should not impl Ord, and should impl PartialOrd differently (?) #16570
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
Comments
CC @aturon |
Discuss thread with these points listed: Perhaps as part of the collections restructuring support for multiple orderings will have to be invented somehow. |
I think all containers should implement ordering as a lexicographic comparison. There are separate methods for checking for a subset / superset already, and we would lose the nice |
@thestinger Lexicographic comparisons are crazy for set types because sets are unordered and the only natural ordering used on them is subset inclusion. For ordered containers, you're right, they make sense (and set inclusion doesn't). |
The sole reason |
Ok, thanks. I was misunderstanding the implied semantics of - |
Alright, satisfied that this has been addressed: Lexicographic ordering is useful and standard. |
Currently, sets that have some notion of an ordering over their elements (TreeSet and BitvSet, at least) implement Ord in terms of the lexicographic ordering of their contents. However, as @apoelstra notes in #16559 it may be more natural for sets to be ordered by inclusion. That is,
a<=b
ifa subseteq b
.However, there is no total ordering over set inclusion. It instead forms a diamond-shaped DAG. Thus, Sets would not implement Ord under this scheme. In fact, almost all pairs of sets would have
cmp
yieldNone
, which makes it a not-very-useful operator for generic comparison. Further, inclusion relationships are already provided by the actual Set api.The text was updated successfully, but these errors were encountered: