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 PartialOrd for HashSet #15647

Closed
wants to merge 2 commits into from
Closed

Conversation

nham
Copy link
Contributor

@nham nham commented Jul 13, 2014

cc #15294

Does it make sense to just implement PartialOrd for every type that implements Set? There is a well-defined partial order on sets based on set inclusion. I'm thinking something like this:

impl<T, S: Set<T>> PartialOrd for S {
    fn partial_cmp(&self, other: &S) -> Option<Ordering> {
        match (self.is_subset(other), other.is_subset(self)) {
            (true, true) => Some(Equal),
            (true, false) => Some(Less),
            (false, true) => Some(Greater),
            (false, false) => None
        }
    }
}

@nham nham changed the title Implement Hash for HashMap and HashSet and PartialOrd for HashSet Implement Hash for HashMap and HashSet, PartialOrd for HashSet Jul 13, 2014
@nham nham changed the title Implement Hash for HashMap and HashSet, PartialOrd for HashSet Implement Hash for HashMap and HashSet, and PartialOrd for HashSet Jul 13, 2014
@thestinger
Copy link
Contributor

I don't think so. We've been consistent in using PartialOrd and Ord as lexicographic orderings, including for types like TreeSet. You can't have it both ways, and it would be incredibly confusing to have it use one definition for some types (HashSet) and another definition for others (TreeSet).

@nham
Copy link
Contributor Author

nham commented Jul 13, 2014

Hmm, you're right. I don't know why I thought this would work. I will nix the Hash implementations for now, I need to study the code more closely.

@nham nham changed the title Implement Hash for HashMap and HashSet, and PartialOrd for HashSet Implement PartialOrd for HashSet Jul 13, 2014
@nham
Copy link
Contributor Author

nham commented Jul 13, 2014

@thestinger Okay, I see what you mean. So to keep it in alignment with the way TreeSet works, for example, we'd need some way to iterate through the HashSet in order, and then we could use the same comparison method that TreeSet uses.

@nham
Copy link
Contributor Author

nham commented Jul 13, 2014

Although this seems counterintuitive to me. If I'm comparing two sets, I would expect the usual partial order from math.

@nham nham closed this Jul 21, 2014
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.

None yet

2 participants