Skip to content

Commit b662aa5

Browse files
sfackleralexcrichton
authored andcommitted
Implement Eq for HashSet and HashMap
Also fix documentation references to PartialEq.
1 parent 1bde6e3 commit b662aa5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/libstd/collections/hashmap.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,8 @@ impl DefaultResizePolicy {
684684
/// denial-of-service attacks (Hash DoS). This behaviour can be
685685
/// overridden with one of the constructors.
686686
///
687-
/// It is required that the keys implement the `PartialEq` and `Hash` traits, although
688-
/// this can frequently be achieved by using `#[deriving(PartialEq, Hash)]`.
687+
/// It is required that the keys implement the `Eq` and `Hash` traits, although
688+
/// this can frequently be achieved by using `#[deriving(Eq, Hash)]`.
689689
///
690690
/// Relevant papers/articles:
691691
///
@@ -1422,6 +1422,8 @@ impl<K: Eq + Hash<S>, V: PartialEq, S, H: Hasher<S>> PartialEq for HashMap<K, V,
14221422
}
14231423
}
14241424

1425+
impl<K: Eq + Hash<S>, V: Eq, S, H: Hasher<S>> Eq for HashMap<K, V, H> {}
1426+
14251427
impl<K: Eq + Hash<S> + Show, V: Show, S, H: Hasher<S>> Show for HashMap<K, V, H> {
14261428
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14271429
try!(write!(f, r"\{"));
@@ -1486,7 +1488,7 @@ pub type SetMoveItems<K> =
14861488

14871489
/// An implementation of a hash set using the underlying representation of a
14881490
/// HashMap where the value is (). As with the `HashMap` type, a `HashSet`
1489-
/// requires that the elements implement the `PartialEq` and `Hash` traits.
1491+
/// requires that the elements implement the `Eq` and `Hash` traits.
14901492
#[deriving(Clone)]
14911493
pub struct HashSet<T, H = sip::SipHasher> {
14921494
map: HashMap<T, (), H>
@@ -1500,6 +1502,8 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> PartialEq for HashSet<T, H> {
15001502
}
15011503
}
15021504

1505+
impl<T: Eq + Hash<S>, S, H: Hasher<S>> Eq for HashSet<T, H> {}
1506+
15031507
impl<T: Eq + Hash<S>, S, H: Hasher<S>> Container for HashSet<T, H> {
15041508
fn len(&self) -> uint { self.map.len() }
15051509
}

0 commit comments

Comments
 (0)