mod impls {
use prelude::*;
- use borrow::{Cow, ToOwned};
use mem;
use num::Int;
use super::*;
(*self as uint).hash(state);
}
}
-
- impl<'a, T, B: ?Sized, S: Hasher> Hash<S> for Cow<'a, T, B>
- where B: Hash<S> + ToOwned<T>
- {
- #[inline]
- fn hash(&self, state: &mut S) {
- Hash::hash(&**self, state)
- }
- }
}
#[cfg(not(stage0))]
mod impls {
use prelude::*;
- use borrow::{Cow, ToOwned};
use slice;
use super::*;
}
)*}
}
+
+ impl_write! {
+ (u8, write_u8),
+ (u16, write_u16),
+ (u32, write_u32),
+ (u64, write_u64),
+ (usize, write_usize),
+ (i8, write_i8),
+ (i16, write_i16),
+ (i32, write_i32),
+ (i64, write_i64),
+ (isize, write_isize),
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl Hash for bool {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ state.write_u8(*self as u8)
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl Hash for char {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ state.write_u32(*self as u32)
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl Hash for str {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ state.write(self.as_bytes());
+ state.write_u8(0xff)
+ }
+ }
+
+ macro_rules! impl_hash_tuple {
+ () => (
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl Hash for () {
+ fn hash<H: Hasher>(&self, _state: &mut H) {}
+ }
+ );
+
+ ( $($name:ident)+) => (
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<$($name: Hash),*> Hash for ($($name,)*) {
+ #[allow(non_snake_case)]
+ fn hash<S: Hasher>(&self, state: &mut S) {
+ let ($(ref $name,)*) = *self;
+ $($name.hash(state);)*
+ }
+ }
+ );
+ }
+
+ impl_hash_tuple! {}
+ impl_hash_tuple! { A }
+ impl_hash_tuple! { A B }
+ impl_hash_tuple! { A B C }
+ impl_hash_tuple! { A B C D }
+ impl_hash_tuple! { A B C D E }
+ impl_hash_tuple! { A B C D E F }
+ impl_hash_tuple! { A B C D E F G }
+ impl_hash_tuple! { A B C D E F G H }
+ impl_hash_tuple! { A B C D E F G H I }
+ impl_hash_tuple! { A B C D E F G H I J }
+ impl_hash_tuple! { A B C D E F G H I J K }
+ impl_hash_tuple! { A B C D E F G H I J K L }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<T: Hash> Hash for [T] {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.len().hash(state);
+ Hash::hash_slice(self, state)
+ }
+ }
+
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, T: ?Sized + Hash> Hash for &'a T {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ (**self).hash(state);
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, T: ?Sized + Hash> Hash for &'a mut T {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ (**self).hash(state);
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<T> Hash for *const T {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ state.write_usize(*self as usize)
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<T> Hash for *mut T {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ state.write_usize(*self as usize)
+ }
+ }
+
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<'a, T, B: ?Sized> Hash for Cow<'a, T, B>
+ where B: Hash + ToOwned<T>
+ {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ Hash::hash(&**self, state)
+ }
+ }
}
use self::SearchResult::*;
use self::VacantEntryState::*;
-use borrow::BorrowFrom;
+use borrow::Borrow;
use clone::Clone;
use cmp::{max, Eq, PartialEq};
use default::Default;
/// If you already have the hash for the key lying around, use
/// search_hashed.
fn search<'a, Q: ?Sized>(&'a self, q: &Q) -> Option<FullBucketImm<'a, K, V>>
- where Q: BorrowFrom<K> + Eq + Hash<H>
+ where K: Borrow<Q>, Q: Eq + Hash<H>
{
let hash = self.make_hash(q);
- search_hashed(&self.table, hash, |k| q.eq(BorrowFrom::borrow_from(k)))
+ search_hashed(&self.table, hash, |k| q.eq(k.borrow()))
.into_option()
}
fn search_mut<'a, Q: ?Sized>(&'a mut self, q: &Q) -> Option<FullBucketMut<'a, K, V>>
- where Q: BorrowFrom<K> + Eq + Hash<H>
+ where K: Borrow<Q>, Q: Eq + Hash<H>
{
let hash = self.make_hash(q);
- search_hashed(&mut self.table, hash, |k| q.eq(BorrowFrom::borrow_from(k)))
+ search_hashed(&mut self.table, hash, |k| q.eq(k.borrow()))
.into_option()
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
- where Q: Hash<H> + Eq + BorrowFrom<K>
+ where K: Borrow<Q>, Q: Hash<H> + Eq
{
self.search(k).map(|bucket| bucket.into_refs().1)
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
- where Q: Hash<H> + Eq + BorrowFrom<K>
+ where K: Borrow<Q>, Q: Hash<H> + Eq
{
self.search(k).is_some()
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
- where Q: Hash<H> + Eq + BorrowFrom<K>
+ where K: Borrow<Q>, Q: Hash<H> + Eq
{
self.search_mut(k).map(|bucket| bucket.into_mut_refs().1)
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
- where Q: Hash<H> + Eq + BorrowFrom<K>
+ where K: Borrow<Q>, Q: Hash<H> + Eq
{
if self.table.size() == 0 {
return None
#[stable(feature = "rust1", since = "1.0.0")]
impl<K, Q: ?Sized, V, S, H> Index<Q> for HashMap<K, V, S>
- where K: Eq + Hash<H>,
- Q: Eq + Hash<H> + BorrowFrom<K>,
+ where K: Eq + Hash<H> + Borrow<Q>,
+ Q: Eq + Hash<H>,
S: HashState<Hasher=H>,
H: hash::Hasher<Output=u64>
{
#[stable(feature = "rust1", since = "1.0.0")]
impl<K, V, S, H, Q: ?Sized> IndexMut<Q> for HashMap<K, V, S>
- where K: Eq + Hash<H>,
- Q: Eq + Hash<H> + BorrowFrom<K>,
+ where K: Eq + Hash<H> + Borrow<Q>,
+ Q: Eq + Hash<H>,
S: HashState<Hasher=H>,
H: hash::Hasher<Output=u64>
{
//
// ignore-lexer-test FIXME #15883
-use borrow::BorrowFrom;
+use borrow::Borrow;
use clone::Clone;
use cmp::{Eq, PartialEq};
use core::marker::Sized;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool
- where Q: BorrowFrom<T> + Hash<H> + Eq
+ where T: Borrow<Q>, Q: Hash<H> + Eq
{
self.map.contains_key(value)
}
/// ```
#[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 T: Borrow<Q>, Q: Hash<H> + Eq
{
self.map.remove(value).is_some()
}