diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-02-17 20:48:07 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-02-18 08:26:20 -0800 |
| commit | f83e23ad7c464c242c2d7ace7212d323980b2bca (patch) | |
| tree | 4af495be32288f7af75d660173a19e412c9a29d8 /src/libstd/collections/hash/set.rs | |
| parent | dfc5c0f1e8799f47f9033bdcc8a7cd8a217620a5 (diff) | |
| download | rust-f83e23ad7c464c242c2d7ace7212d323980b2bca.tar.gz rust-f83e23ad7c464c242c2d7ace7212d323980b2bca.zip | |
std: Stabilize the `hash` module
This commit is an implementation of [RFC 823][rfc] which is another pass over the `std::hash` module for stabilization. The contents of the module were not entirely marked stable, but some portions which remained quite similar to the previous incarnation are now marked `#[stable]`. Specifically: [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0823-hash-simplification.md * `std::hash` is now stable (the name) * `Hash` is now stable * `Hash::hash` is now stable * `Hasher` is now stable * `SipHasher` is now stable * `SipHasher::new` and `new_with_keys` are now stable * `Hasher for SipHasher` is now stable * Many `Hash` implementations are now stable All other portions of the `hash` module remain `#[unstable]` as they are less commonly used and were recently redesigned. This commit is a breaking change due to the modifications to the `std::hash` API and more details can be found on the [RFC][rfc]. Closes #22467 [breaking-change]
Diffstat (limited to 'src/libstd/collections/hash/set.rs')
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 121 |
1 files changed, 48 insertions, 73 deletions
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 5fbbcb3b347..7ff76452c1a 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -17,14 +17,14 @@ use core::marker::Sized; use default::Default; use fmt::Debug; use fmt; -use hash::{self, Hash}; +use hash::Hash; use iter::{ Iterator, IntoIterator, ExactSizeIterator, IteratorExt, FromIterator, Map, Chain, Extend, }; use ops::{BitOr, BitAnd, BitXor, Sub}; use option::Option::{Some, None, self}; -use super::map::{self, HashMap, Keys, INITIAL_CAPACITY, RandomState, Hasher}; +use super::map::{self, HashMap, Keys, INITIAL_CAPACITY, RandomState}; use super::state::HashState; // Future Optimization (FIXME!) @@ -97,7 +97,7 @@ pub struct HashSet<T, S = RandomState> { map: HashMap<T, (), S> } -impl<T: Hash<Hasher> + Eq> HashSet<T, RandomState> { +impl<T: Hash + Eq> HashSet<T, RandomState> { /// Create an empty HashSet. /// /// # Example @@ -128,10 +128,8 @@ impl<T: Hash<Hasher> + Eq> HashSet<T, RandomState> { } } -impl<T, S, H> HashSet<T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H>, - H: hash::Hasher<Output=u64> +impl<T, S> HashSet<T, S> + where T: Eq + Hash, S: HashState { /// Creates a new empty hash set which will use the given hasher to hash /// keys. @@ -462,7 +460,7 @@ impl<T, S, H> HashSet<T, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool - where Q: BorrowFrom<T> + Hash<H> + Eq + where Q: BorrowFrom<T> + Hash + Eq { self.map.contains_key(value) } @@ -572,17 +570,15 @@ impl<T, S, H> HashSet<T, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool - where Q: BorrowFrom<T> + Hash<H> + Eq + where Q: BorrowFrom<T> + Hash + Eq { self.map.remove(value).is_some() } } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, S, H> PartialEq for HashSet<T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H>, - H: hash::Hasher<Output=u64> +impl<T, S> PartialEq for HashSet<T, S> + where T: Eq + Hash, S: HashState { fn eq(&self, other: &HashSet<T, S>) -> bool { if self.len() != other.len() { return false; } @@ -592,17 +588,14 @@ impl<T, S, H> PartialEq for HashSet<T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, S, H> Eq for HashSet<T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H>, - H: hash::Hasher<Output=u64> +impl<T, S> Eq for HashSet<T, S> + where T: Eq + Hash, S: HashState {} #[stable(feature = "rust1", since = "1.0.0")] -impl<T, S, H> fmt::Debug for HashSet<T, S> - where T: Eq + Hash<H> + fmt::Debug, - S: HashState<Hasher=H>, - H: hash::Hasher<Output=u64> +impl<T, S> fmt::Debug for HashSet<T, S> + where T: Eq + Hash + fmt::Debug, + S: HashState { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "HashSet {{")); @@ -617,10 +610,9 @@ impl<T, S, H> fmt::Debug for HashSet<T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, S, H> FromIterator<T> for HashSet<T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H> + Default, - H: hash::Hasher<Output=u64> +impl<T, S> FromIterator<T> for HashSet<T, S> + where T: Eq + Hash, + S: HashState + Default, { fn from_iter<I: Iterator<Item=T>>(iter: I) -> HashSet<T, S> { let lower = iter.size_hint().0; @@ -631,10 +623,9 @@ impl<T, S, H> FromIterator<T> for HashSet<T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, S, H> Extend<T> for HashSet<T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H>, - H: hash::Hasher<Output=u64> +impl<T, S> Extend<T> for HashSet<T, S> + where T: Eq + Hash, + S: HashState, { fn extend<I: Iterator<Item=T>>(&mut self, iter: I) { for k in iter { @@ -644,10 +635,9 @@ impl<T, S, H> Extend<T> for HashSet<T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, S, H> Default for HashSet<T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H> + Default, - H: hash::Hasher<Output=u64> +impl<T, S> Default for HashSet<T, S> + where T: Eq + Hash, + S: HashState + Default, { #[stable(feature = "rust1", since = "1.0.0")] fn default() -> HashSet<T, S> { @@ -656,10 +646,9 @@ impl<T, S, H> Default for HashSet<T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, 'b, T, S, H> BitOr<&'b HashSet<T, S>> for &'a HashSet<T, S> - where T: Eq + Hash<H> + Clone, - S: HashState<Hasher=H> + Default, - H: hash::Hasher<Output=u64> +impl<'a, 'b, T, S> BitOr<&'b HashSet<T, S>> for &'a HashSet<T, S> + where T: Eq + Hash + Clone, + S: HashState + Default, { type Output = HashSet<T, S>; @@ -689,10 +678,9 @@ impl<'a, 'b, T, S, H> BitOr<&'b HashSet<T, S>> for &'a HashSet<T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, 'b, T, S, H> BitAnd<&'b HashSet<T, S>> for &'a HashSet<T, S> - where T: Eq + Hash<H> + Clone, - S: HashState<Hasher=H> + Default, - H: hash::Hasher<Output=u64> +impl<'a, 'b, T, S> BitAnd<&'b HashSet<T, S>> for &'a HashSet<T, S> + where T: Eq + Hash + Clone, + S: HashState + Default, { type Output = HashSet<T, S>; @@ -722,10 +710,9 @@ impl<'a, 'b, T, S, H> BitAnd<&'b HashSet<T, S>> for &'a HashSet<T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, 'b, T, S, H> BitXor<&'b HashSet<T, S>> for &'a HashSet<T, S> - where T: Eq + Hash<H> + Clone, - S: HashState<Hasher=H> + Default, - H: hash::Hasher<Output=u64> +impl<'a, 'b, T, S> BitXor<&'b HashSet<T, S>> for &'a HashSet<T, S> + where T: Eq + Hash + Clone, + S: HashState + Default, { type Output = HashSet<T, S>; @@ -755,10 +742,9 @@ impl<'a, 'b, T, S, H> BitXor<&'b HashSet<T, S>> for &'a HashSet<T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, 'b, T, S, H> Sub<&'b HashSet<T, S>> for &'a HashSet<T, S> - where T: Eq + Hash<H> + Clone, - S: HashState<Hasher=H> + Default, - H: hash::Hasher<Output=u64> +impl<'a, 'b, T, S> Sub<&'b HashSet<T, S>> for &'a HashSet<T, S> + where T: Eq + Hash + Clone, + S: HashState + Default, { type Output = HashSet<T, S>; @@ -836,10 +822,8 @@ pub struct Union<'a, T: 'a, S: 'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, S, H> IntoIterator for &'a HashSet<T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H>, - H: hash::Hasher<Output=u64> +impl<'a, T, S> IntoIterator for &'a HashSet<T, S> + where T: Eq + Hash, S: HashState { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -850,10 +834,9 @@ impl<'a, T, S, H> IntoIterator for &'a HashSet<T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, S, H> IntoIterator for HashSet<T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H>, - H: hash::Hasher<Output=u64> +impl<T, S> IntoIterator for HashSet<T, S> + where T: Eq + Hash, + S: HashState { type Item = T; type IntoIter = IntoIter<T>; @@ -900,10 +883,8 @@ impl<'a, K> ExactSizeIterator for Drain<'a, K> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, S, H> Iterator for Intersection<'a, T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H>, - H: hash::Hasher<Output=u64> +impl<'a, T, S> Iterator for Intersection<'a, T, S> + where T: Eq + Hash, S: HashState { type Item = &'a T; @@ -925,10 +906,8 @@ impl<'a, T, S, H> Iterator for Intersection<'a, T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, S, H> Iterator for Difference<'a, T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H>, - H: hash::Hasher<Output=u64> +impl<'a, T, S> Iterator for Difference<'a, T, S> + where T: Eq + Hash, S: HashState { type Item = &'a T; @@ -950,10 +929,8 @@ impl<'a, T, S, H> Iterator for Difference<'a, T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, S, H> Iterator for SymmetricDifference<'a, T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H>, - H: hash::Hasher<Output=u64> +impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S> + where T: Eq + Hash, S: HashState { type Item = &'a T; @@ -962,10 +939,8 @@ impl<'a, T, S, H> Iterator for SymmetricDifference<'a, T, S> } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, S, H> Iterator for Union<'a, T, S> - where T: Eq + Hash<H>, - S: HashState<Hasher=H>, - H: hash::Hasher<Output=u64> +impl<'a, T, S> Iterator for Union<'a, T, S> + where T: Eq + Hash, S: HashState { type Item = &'a T; |
