From 9d2636e8b0525b96c86ee47dc27379e4b9386eac Mon Sep 17 00:00:00 2001 From: nham Date: Sun, 13 Jul 2014 13:02:38 -0400 Subject: [PATCH 1/2] Implement PartialOrd for HashSet --- src/libstd/collections/hashmap.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libstd/collections/hashmap.rs b/src/libstd/collections/hashmap.rs index 098e87243b69c..dc79229935d55 100644 --- a/src/libstd/collections/hashmap.rs +++ b/src/libstd/collections/hashmap.rs @@ -11,7 +11,8 @@ //! Unordered containers, implemented as hash-tables (`HashSet` and `HashMap` types) use clone::Clone; -use cmp::{max, Eq, Equiv, PartialEq}; +use cmp; +use cmp::{max, Eq, Equiv, PartialEq, Ordering}; use collections::{Collection, Mutable, Set, MutableSet, Map, MutableMap}; use default::Default; use fmt::Show; @@ -1499,6 +1500,18 @@ impl, S, H: Hasher> PartialEq for HashSet { impl, S, H: Hasher> Eq for HashSet {} +impl, S, H: Hasher> PartialOrd for HashSet { + #[inline] + fn partial_cmp(&self, other: &HashSet) -> Option { + match (self.is_subset(other), other.is_subset(&self)) { + (true, true) => Some(cmp::Equal), + (true, false) => Some(cmp::Less), + (false, true) => Some(cmp::Greater), + (false, false) => None + } + } +} + impl, S, H: Hasher> Collection for HashSet { fn len(&self) -> uint { self.map.len() } } From 52192cd0d0b5bddafc4c98f254299fb7efdde238 Mon Sep 17 00:00:00 2001 From: nham Date: Sun, 13 Jul 2014 14:21:00 -0400 Subject: [PATCH 2/2] Various fixes. --- src/libstd/collections/hashmap.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/collections/hashmap.rs b/src/libstd/collections/hashmap.rs index dc79229935d55..20c7e1c695d87 100644 --- a/src/libstd/collections/hashmap.rs +++ b/src/libstd/collections/hashmap.rs @@ -12,7 +12,7 @@ use clone::Clone; use cmp; -use cmp::{max, Eq, Equiv, PartialEq, Ordering}; +use cmp::{max, Eq, Equiv, PartialEq, PartialOrd, Ordering}; use collections::{Collection, Mutable, Set, MutableSet, Map, MutableMap}; use default::Default; use fmt::Show; @@ -1503,7 +1503,7 @@ impl, S, H: Hasher> Eq for HashSet {} impl, S, H: Hasher> PartialOrd for HashSet { #[inline] fn partial_cmp(&self, other: &HashSet) -> Option { - match (self.is_subset(other), other.is_subset(&self)) { + match (self.is_subset(other), other.is_subset(self)) { (true, true) => Some(cmp::Equal), (true, false) => Some(cmp::Less), (false, true) => Some(cmp::Greater),