Skip to content

Commit

Permalink
Fix for upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Feb 20, 2015
1 parent cd637ca commit f014882
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions phf/src/map.rs
@@ -1,6 +1,6 @@
//! An immutable map constructed at compile time.
use std::prelude::v1::*;
use std::borrow::BorrowFrom;
use std::borrow::Borrow;
use std::ops::Index;
use std::slice;
use std::fmt;
Expand Down Expand Up @@ -55,7 +55,7 @@ impl<K, V> fmt::Debug for Map<K, V> where K: fmt::Debug, V: fmt::Debug {
}
}

impl<K, V, T: ?Sized> Index<T> for Map<K, V> where T: Eq + PhfHash + BorrowFrom<K> {
impl<K, V, T: ?Sized> Index<T> for Map<K, V> where T: Eq + PhfHash, K: Borrow<T> {
type Output = V;

fn index(&self, k: &T) -> &V {
Expand All @@ -75,31 +75,31 @@ impl<K, V> Map<K, V> {
}

/// Determines if `key` is in the `Map`.
pub fn contains_key<T: ?Sized>(&self, key: &T) -> bool where T: Eq + PhfHash + BorrowFrom<K> {
pub fn contains_key<T: ?Sized>(&self, key: &T) -> bool where T: Eq + PhfHash, K: Borrow<T> {
self.get(key).is_some()
}

/// Returns a reference to the value that `key` maps to.
pub fn get<T: ?Sized>(&self, key: &T) -> Option<&V> where T: Eq + PhfHash + BorrowFrom<K> {
pub fn get<T: ?Sized>(&self, key: &T) -> Option<&V> where T: Eq + PhfHash, K: Borrow<T> {
self.get_entry(key).map(|e| e.1)
}

/// Returns a reference to the map's internal static instance of the given
/// key.
///
/// This can be useful for interning schemes.
pub fn get_key<T: ?Sized>(&self, key: &T) -> Option<&K> where T: Eq + PhfHash + BorrowFrom<K> {
pub fn get_key<T: ?Sized>(&self, key: &T) -> Option<&K> where T: Eq + PhfHash, K: Borrow<T> {
self.get_entry(key).map(|e| e.0)
}

/// Like `get`, but returns both the key and the value.
pub fn get_entry<T: ?Sized>(&self, key: &T) -> Option<(&K, &V)>
where T: Eq + PhfHash + BorrowFrom<K> {
where T: Eq + PhfHash, K: Borrow<T> {
let (g, f1, f2) = key.phf_hash(self.key);
let (d1, d2) = self.disps[(g % (self.disps.len() as u32)) as usize];
let entry = &self.entries[(phf_shared::displace(f1, f2, d1, d2) % (self.entries.len() as u32))
as usize];
let b: &T = BorrowFrom::borrow_from(&entry.0);
let b: &T = entry.0.borrow();
if b == key {
Some((&entry.0, &entry.1))
} else {
Expand Down
18 changes: 9 additions & 9 deletions phf/src/ordered_map.rs
@@ -1,6 +1,6 @@
//! An order-preserving immutable map constructed at compile time.
use std::prelude::v1::*;
use std::borrow::BorrowFrom;
use std::borrow::Borrow;
use std::iter::{IntoIterator, RandomAccessIterator};
use std::ops::Index;
use std::fmt;
Expand Down Expand Up @@ -61,7 +61,7 @@ impl<K, V> fmt::Debug for OrderedMap<K, V> where K: fmt::Debug, V: fmt::Debug {
}
}

impl<K, V, T: ?Sized> Index<T> for OrderedMap<K, V> where T: Eq + PhfHash + BorrowFrom<K> {
impl<K, V, T: ?Sized> Index<T> for OrderedMap<K, V> where T: Eq + PhfHash, K: Borrow<T> {
type Output = V;

fn index(&self, k: &T) -> &V {
Expand All @@ -81,44 +81,44 @@ impl<K, V> OrderedMap<K, V> {
}

/// Returns a reference to the value that `key` maps to.
pub fn get<T: ?Sized>(&self, key: &T) -> Option<&V> where T: Eq + PhfHash + BorrowFrom<K> {
pub fn get<T: ?Sized>(&self, key: &T) -> Option<&V> where T: Eq + PhfHash, K: Borrow<T> {
self.get_entry(key).map(|e| e.1)
}

/// Returns a reference to the map's internal static instance of the given
/// key.
///
/// This can be useful for interning schemes.
pub fn get_key<T: ?Sized>(&self, key: &T) -> Option<&K> where T: Eq + PhfHash + BorrowFrom<K> {
pub fn get_key<T: ?Sized>(&self, key: &T) -> Option<&K> where T: Eq + PhfHash, K: Borrow<T> {
self.get_entry(key).map(|e| e.0)
}

/// Determines if `key` is in the `Map`.
pub fn contains_key<T: ?Sized>(&self, key: &T) -> bool where T: Eq + PhfHash + BorrowFrom<K> {
pub fn contains_key<T: ?Sized>(&self, key: &T) -> bool where T: Eq + PhfHash, K: Borrow<T> {
self.get(key).is_some()
}

/// Returns the index of the key within the list used to initialize
/// the ordered map.
pub fn get_index<T: ?Sized>(&self, key: &T) -> Option<usize>
where T: Eq + PhfHash + BorrowFrom<K> {
where T: Eq + PhfHash, K: Borrow<T> {
self.get_internal(key).map(|(i, _)| i)
}

/// Like `get`, but returns both the key and the value.
pub fn get_entry<T: ?Sized>(&self, key: &T) -> Option<(&K, &V)>
where T: Eq + PhfHash + BorrowFrom<K> {
where T: Eq + PhfHash, K: Borrow<T> {
self.get_internal(key).map(|(_, e)| e)
}

fn get_internal<T: ?Sized>(&self, key: &T) -> Option<(usize, (&K, &V))>
where T: Eq + PhfHash + BorrowFrom<K> {
where T: Eq + PhfHash, K: Borrow<T> {
let (g, f1, f2) = key.phf_hash(self.key);
let (d1, d2) = self.disps[(g % (self.disps.len() as u32)) as usize];
let idx = self.idxs[(phf_shared::displace(f1, f2, d1, d2) % (self.idxs.len() as u32)) as usize];
let entry = &self.entries[idx];

let b: &T = BorrowFrom::borrow_from(&entry.0);
let b: &T = entry.0.borrow();
if b == key {
Some((idx, (&entry.0, &entry.1)))
} else {
Expand Down
8 changes: 4 additions & 4 deletions phf/src/ordered_set.rs
@@ -1,6 +1,6 @@
//! An order-preserving immutable set constructed at compile time.
use std::prelude::v1::*;
use std::borrow::BorrowFrom;
use std::borrow::Borrow;
use std::iter::{IntoIterator, RandomAccessIterator};
use std::fmt;
use ordered_map;
Expand Down Expand Up @@ -67,19 +67,19 @@ impl<T> OrderedSet<T> {
/// key.
///
/// This can be useful for interning schemes.
pub fn get_key<U: ?Sized>(&self, key: &U) -> Option<&T> where U: Eq + PhfHash + BorrowFrom<T> {
pub fn get_key<U: ?Sized>(&self, key: &U) -> Option<&T> where U: Eq + PhfHash, T: Borrow<U> {
self.map.get_key(key)
}

/// Returns the index of the key within the list used to initialize
/// the ordered set.
pub fn get_index<U: ?Sized>(&self, key: &U) -> Option<usize>
where U: Eq + PhfHash + BorrowFrom<T> {
where U: Eq + PhfHash, T: Borrow<U> {
self.map.get_index(key)
}

/// Returns true if `value` is in the `Set`.
pub fn contains<U: ?Sized>(&self, value: &U) -> bool where U: Eq + PhfHash + BorrowFrom<T> {
pub fn contains<U: ?Sized>(&self, value: &U) -> bool where U: Eq + PhfHash, T: Borrow<U> {
self.map.contains_key(value)
}

Expand Down
6 changes: 3 additions & 3 deletions phf/src/set.rs
@@ -1,6 +1,6 @@
//! An immutable set constructed at compile time.
use std::prelude::v1::*;
use std::borrow::BorrowFrom;
use std::borrow::Borrow;
use std::iter::IntoIterator;
use std::fmt;

Expand Down Expand Up @@ -66,12 +66,12 @@ impl<T> Set<T> {
/// key.
///
/// This can be useful for interning schemes.
pub fn get_key<U: ?Sized>(&self, key: &U) -> Option<&T> where U: Eq + PhfHash + BorrowFrom<T> {
pub fn get_key<U: ?Sized>(&self, key: &U) -> Option<&T> where U: Eq + PhfHash, T: Borrow<U> {
self.map.get_key(key)
}

/// Returns true if `value` is in the `Set`.
pub fn contains<U: ?Sized>(&self, value: &U) -> bool where U: Eq + PhfHash + BorrowFrom<T> {
pub fn contains<U: ?Sized>(&self, value: &U) -> bool where U: Eq + PhfHash, T: Borrow<U> {
self.map.contains_key(value)
}

Expand Down
6 changes: 3 additions & 3 deletions phf_shared/src/lib.rs
Expand Up @@ -8,7 +8,7 @@ extern crate core;

use std::slice::AsSlice;
use std::str::StrExt;
use std::hash::{Writer, Hasher, Hash, SipHasher};
use std::hash::{Hasher, Hash, SipHasher};

#[cfg(feature = "core")]
mod std {
Expand Down Expand Up @@ -61,7 +61,7 @@ impl PhfHash for [u8] {
#[inline]
fn phf_hash(&self, seed: u64) -> (u32, u32, u32) {
let mut state = SipHasher::new_with_keys(seed, 0);
state.write(self);
Hasher::write(&mut state, self);
split(state.finish())
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ macro_rules! array_impl(
#[inline]
fn phf_hash(&self, seed: u64) -> (u32, u32, u32) {
let mut hasher = SipHasher::new_with_keys(seed, 0);
hasher.write(self.as_slice());
Hasher::write(&mut hasher, self);
split(hasher.finish())
}
}
Expand Down

0 comments on commit f014882

Please sign in to comment.