From 0b22188f5767a0a125d01ed8b176ce19fef95cad Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 9 Jan 2015 08:56:14 -0800 Subject: [PATCH] Fix for upstream changes --- phf/src/lib.rs | 3 +- phf/src/map.rs | 35 ++++++++++++++------ phf/src/ordered_map.rs | 55 ++++++++++++++++++++----------- phf/src/ordered_set.rs | 33 ++++++++++++++----- phf/src/set.rs | 27 +++++++++++---- phf/tests/test.rs | 75 +++++++++++++++++++++--------------------- phf_mac/src/lib.rs | 4 +-- phf_mac/src/util.rs | 16 ++++----- phf_shared/src/lib.rs | 16 +++++---- 9 files changed, 165 insertions(+), 99 deletions(-) diff --git a/phf/src/lib.rs b/phf/src/lib.rs index c1eb02c0..046853c0 100644 --- a/phf/src/lib.rs +++ b/phf/src/lib.rs @@ -1,9 +1,10 @@ //! Compile time optimized maps and sets. //! //! Keys can be string literals, byte string literals, byte literals, char -//! literals, or any of the fixed-size integral types. +//! literals, or any of the fixed-size isizeegral types. #![doc(html_root_url="https://sfackler.github.io/doc")] #![warn(missing_docs)] +#![allow(unstable)] #![feature(old_orphan_check)] #![no_std] diff --git a/phf/src/map.rs b/phf/src/map.rs index f60a527b..a74012ba 100644 --- a/phf/src/map.rs +++ b/phf/src/map.rs @@ -17,7 +17,7 @@ use phf_shared; /// #[plugin] #[no_link] /// extern crate phf_mac; /// -/// static MY_MAP: phf::Map<&'static str, int> = phf_map! { +/// static MY_MAP: phf::Map<&'static str, isize> = phf_map! { /// "hello" => 10, /// "world" => 11, /// }; @@ -39,7 +39,7 @@ pub struct Map { pub entries: &'static [(K, V)], } -impl fmt::Show for Map where K: fmt::Show, V: fmt::Show { +impl fmt::String for Map where K: fmt::String, V: fmt::String { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "{{")); let mut first = true; @@ -54,6 +54,21 @@ impl fmt::Show for Map where K: fmt::Show, V: fmt::Show { } } +impl fmt::Show for Map where K: fmt::Show, V: fmt::Show { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + try!(write!(fmt, "{{")); + let mut first = true; + for (k, v) in self.entries() { + if !first { + try!(write!(fmt, ", ")); + } + try!(write!(fmt, "{:?}: {:?}", k, v)); + first = false; + } + write!(fmt, "}}") + } +} + impl Index for Map where T: Eq + PhfHash + BorrowFrom { type Output = V; @@ -69,7 +84,7 @@ impl Map { } /// Returns the number of entries in the `Map`. - pub fn len(&self) -> uint { + pub fn len(&self) -> usize { self.entries.len() } @@ -83,10 +98,10 @@ impl Map { self.get_entry(key).map(|e| e.1) } - /// Returns a reference to the map's internal static instance of the given + /// Returns a reference to the map's isizeernal static instance of the given /// key. /// - /// This can be useful for interning schemes. + /// This can be useful for isizeerning schemes. pub fn get_key(&self, key: &T) -> Option<&K> where T: Eq + PhfHash + BorrowFrom { self.get_entry(key).map(|e| e.0) } @@ -95,9 +110,9 @@ impl Map { pub fn get_entry(&self, key: &T) -> Option<(&K, &V)> where T: Eq + PhfHash + BorrowFrom { let (g, f1, f2) = key.phf_hash(self.key); - let (d1, d2) = self.disps[(g % (self.disps.len() as u32)) as uint]; + 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 uint]; + as usize]; let b: &T = BorrowFrom::borrow_from(&entry.0); if b == key { Some((&entry.0, &entry.1)) @@ -140,7 +155,7 @@ impl<'a, K, V> Iterator for Entries<'a, K, V> { self.iter.next().map(|&(ref k, ref v)| (k, v)) } - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } @@ -165,7 +180,7 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> { self.iter.next().map(|e| e.0) } - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } @@ -190,7 +205,7 @@ impl<'a, K, V> Iterator for Values<'a, K, V> { self.iter.next().map(|e| e.1) } - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } diff --git a/phf/src/ordered_map.rs b/phf/src/ordered_map.rs index 231d30d0..d281274a 100644 --- a/phf/src/ordered_map.rs +++ b/phf/src/ordered_map.rs @@ -22,7 +22,7 @@ use phf_shared; /// #[plugin] #[no_link] /// extern crate phf_mac; /// -/// static MY_MAP: phf::OrderedMap<&'static str, int> = phf_ordered_map! { +/// static MY_MAP: phf::OrderedMap<&'static str, isize> = phf_ordered_map! { /// "hello" => 10, /// "world" => 11, /// }; @@ -41,12 +41,27 @@ pub struct OrderedMap { #[doc(hidden)] pub disps: &'static [(u32, u32)], #[doc(hidden)] - pub idxs: &'static [uint], + pub idxs: &'static [usize], #[doc(hidden)] pub entries: &'static [(K, V)], } impl fmt::Show for OrderedMap where K: fmt::Show, V: fmt::Show { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + try!(write!(fmt, "{{")); + let mut first = true; + for (k, v) in self.entries() { + if !first { + try!(write!(fmt, ", ")); + } + try!(write!(fmt, "{:?}: {:?}", k, v)); + first = false; + } + write!(fmt, "}}") + } +} + +impl fmt::String for OrderedMap where K: fmt::String, V: fmt::String { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "{{")); let mut first = true; @@ -71,7 +86,7 @@ impl Index for OrderedMap where T: Eq + PhfHash + Borr impl OrderedMap { /// Returns the number of entries in the `Map`. - pub fn len(&self) -> uint { + pub fn len(&self) -> usize { self.entries.len() } @@ -85,10 +100,10 @@ impl OrderedMap { self.get_entry(key).map(|e| e.1) } - /// Returns a reference to the map's internal static instance of the given + /// Returns a reference to the map's isizeernal static instance of the given /// key. /// - /// This can be useful for interning schemes. + /// This can be useful for isizeerning schemes. pub fn get_key(&self, key: &T) -> Option<&K> where T: Eq + PhfHash + BorrowFrom { self.get_entry(key).map(|e| e.0) } @@ -100,22 +115,22 @@ impl OrderedMap { /// Returns the index of the key within the list used to initialize /// the ordered map. - pub fn get_index(&self, key: &T) -> Option + pub fn get_index(&self, key: &T) -> Option where T: Eq + PhfHash + BorrowFrom { - self.get_internal(key).map(|(i, _)| i) + self.get_isizeernal(key).map(|(i, _)| i) } /// Like `get`, but returns both the key and the value. pub fn get_entry(&self, key: &T) -> Option<(&K, &V)> where T: Eq + PhfHash + BorrowFrom { - self.get_internal(key).map(|(_, e)| e) + self.get_isizeernal(key).map(|(_, e)| e) } - fn get_internal(&self, key: &T) -> Option<(uint, (&K, &V))> + fn get_isizeernal(&self, key: &T) -> Option<(usize, (&K, &V))> where T: Eq + PhfHash + BorrowFrom { let (g, f1, f2) = key.phf_hash(self.key); - let (d1, d2) = self.disps[(g % (self.disps.len() as u32)) as uint]; - let idx = self.idxs[(phf_shared::displace(f1, f2, d1, d2) % (self.idxs.len() as u32)) as uint]; + 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); @@ -160,7 +175,7 @@ impl<'a, K, V> Iterator for Entries<'a, K, V> { self.iter.next().map(|e| (&e.0, &e.1)) } - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } @@ -172,11 +187,11 @@ impl<'a, K, V> DoubleEndedIterator for Entries<'a, K, V> { } impl<'a, K, V> RandomAccessIterator for Entries<'a, K, V> { - fn indexable(&self) -> uint { + fn indexable(&self) -> usize { self.iter.indexable() } - fn idx(&mut self, index: uint) -> Option<(&'a K, &'a V)> { + fn idx(&mut self, index: usize) -> Option<(&'a K, &'a V)> { self.iter.idx(index).map(|e| (&e.0, &e.1)) } } @@ -195,7 +210,7 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> { self.iter.next().map(|e| e.0) } - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } @@ -207,11 +222,11 @@ impl<'a, K, V> DoubleEndedIterator for Keys<'a, K, V> { } impl<'a, K, V> RandomAccessIterator for Keys<'a, K, V> { - fn indexable(&self) -> uint { + fn indexable(&self) -> usize { self.iter.indexable() } - fn idx(&mut self, index: uint) -> Option<&'a K> { + fn idx(&mut self, index: usize) -> Option<&'a K> { self.iter.idx(index).map(|e| e.0) } } @@ -230,7 +245,7 @@ impl<'a, K, V> Iterator for Values<'a, K, V> { self.iter.next().map(|e| e.1) } - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } @@ -242,11 +257,11 @@ impl<'a, K, V> DoubleEndedIterator for Values<'a, K, V> { } impl<'a, K, V> RandomAccessIterator for Values<'a, K, V> { - fn indexable(&self) -> uint { + fn indexable(&self) -> usize { self.iter.indexable() } - fn idx(&mut self, index: uint) -> Option<&'a V> { + fn idx(&mut self, index: usize) -> Option<&'a V> { self.iter.idx(index).map(|e| e.1) } } diff --git a/phf/src/ordered_set.rs b/phf/src/ordered_set.rs index 5093425f..1bb29662 100644 --- a/phf/src/ordered_set.rs +++ b/phf/src/ordered_set.rs @@ -37,7 +37,7 @@ pub struct OrderedSet { pub map: OrderedMap, } -impl fmt::Show for OrderedSet where T: fmt::Show { +impl fmt::String for OrderedSet where T: fmt::String { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "{{")); let mut first = true; @@ -52,9 +52,24 @@ impl fmt::Show for OrderedSet where T: fmt::Show { } } +impl fmt::Show for OrderedSet where T: fmt::Show { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + try!(write!(fmt, "{{")); + let mut first = true; + for entry in self.iter() { + if !first { + try!(write!(fmt, ", ")); + } + try!(write!(fmt, "{:?}", entry)); + first = false; + } + write!(fmt, "}}") + } +} + impl OrderedSet { /// Returns the number of elements in the `OrderedSet`. - pub fn len(&self) -> uint { + pub fn len(&self) -> usize { self.map.len() } @@ -63,17 +78,17 @@ impl OrderedSet { self.len() == 0 } - /// Returns a reference to the set's internal static instance of the given + /// Returns a reference to the set's isizeernal static instance of the given /// key. /// - /// This can be useful for interning schemes. + /// This can be useful for isizeerning schemes. pub fn get_key(&self, key: &U) -> Option<&T> where U: Eq + PhfHash + BorrowFrom { self.map.get_key(key) } /// Returns the index of the key within the list used to initialize /// the ordered set. - pub fn get_index(&self, key: &U) -> Option + pub fn get_index(&self, key: &U) -> Option where U: Eq + PhfHash + BorrowFrom { self.map.get_index(key) } @@ -94,7 +109,7 @@ impl OrderedSet { impl OrderedSet where T: Eq + PhfHash { /// Returns true if `other` shares no elements with `self`. #[inline] - pub fn is_disjoint(&self, other: &OrderedSet) -> bool { + pub fn is_disjoisize(&self, other: &OrderedSet) -> bool { !self.iter().any(|value| other.contains(value)) } @@ -125,7 +140,7 @@ impl<'a, T> Iterator for Iter<'a, T> { } #[inline] - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } @@ -139,12 +154,12 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> { impl<'a, T> RandomAccessIterator for Iter<'a, T> { #[inline] - fn indexable(&self) -> uint { + fn indexable(&self) -> usize { self.iter.indexable() } #[inline] - fn idx(&mut self, index: uint) -> Option<&'a T> { + fn idx(&mut self, index: usize) -> Option<&'a T> { self.iter.idx(index) } } diff --git a/phf/src/set.rs b/phf/src/set.rs index a8171476..ffbaf964 100644 --- a/phf/src/set.rs +++ b/phf/src/set.rs @@ -35,7 +35,7 @@ pub struct Set { pub map: Map } -impl fmt::Show for Set where T: fmt::Show { +impl fmt::String for Set where T: fmt::String { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "{{")); let mut first = true; @@ -50,9 +50,24 @@ impl fmt::Show for Set where T: fmt::Show { } } +impl fmt::Show for Set where T: fmt::Show { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + try!(write!(fmt, "{{")); + let mut first = true; + for entry in self.iter() { + if !first { + try!(write!(fmt, ", ")); + } + try!(write!(fmt, "{:?}", entry)); + first = false; + } + write!(fmt, "}}") + } +} + impl Set { /// Returns the number of elements in the `Set`. - pub fn len(&self) -> uint { + pub fn len(&self) -> usize { self.map.len() } @@ -61,10 +76,10 @@ impl Set { self.len() == 0 } - /// Returns a reference to the set's internal static instance of the given + /// Returns a reference to the set's isizeernal static instance of the given /// key. /// - /// This can be useful for interning schemes. + /// This can be useful for isizeerning schemes. pub fn get_key(&self, key: &U) -> Option<&T> where U: Eq + PhfHash + BorrowFrom { self.map.get_key(key) } @@ -84,7 +99,7 @@ impl Set { impl Set where T: Eq + PhfHash { /// Returns true if `other` shares no elements with `self`. - pub fn is_disjoint(&self, other: &Set) -> bool { + pub fn is_disjoisize(&self, other: &Set) -> bool { !self.iter().any(|value| other.contains(value)) } @@ -111,7 +126,7 @@ impl<'a, T> Iterator for Iter<'a, T> { self.iter.next() } - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } diff --git a/phf/tests/test.rs b/phf/tests/test.rs index 8c382b87..4b108bc9 100644 --- a/phf/tests/test.rs +++ b/phf/tests/test.rs @@ -1,3 +1,4 @@ +#![allow(unstable)] #![feature(plugin)] #[plugin] #[no_link] @@ -9,18 +10,18 @@ mod map { use phf; #[allow(dead_code)] - static TRAILING_COMMA: phf::Map<&'static str, int> = phf_map!( + static TRAILING_COMMA: phf::Map<&'static str, isize> = phf_map!( "foo" => 10, ); #[allow(dead_code)] - static NO_TRAILING_COMMA: phf::Map<&'static str, int> = phf_map!( + static NO_TRAILING_COMMA: phf::Map<&'static str, isize> = phf_map!( "foo" => 10 ); #[test] fn test_two() { - static MAP: phf::Map<&'static str, int> = phf_map!( + static MAP: phf::Map<&'static str, isize> = phf_map!( "foo" => 10, "bar" => 11, ); @@ -32,11 +33,11 @@ mod map { #[test] fn test_entries() { - static MAP: phf::Map<&'static str, int> = phf_map!( + static MAP: phf::Map<&'static str, isize> = phf_map!( "foo" => 10, "bar" => 11, ); - let hash = MAP.entries().map(|(&k, &v)| (k, v)).collect::>(); + let hash = MAP.entries().map(|(&k, &v)| (k, v)).collect::>(); assert!(Some(&10) == hash.get(&("foo"))); assert!(Some(&11) == hash.get(&("bar"))); assert_eq!(2, hash.len()); @@ -44,7 +45,7 @@ mod map { #[test] fn test_keys() { - static MAP: phf::Map<&'static str, int> = phf_map!( + static MAP: phf::Map<&'static str, isize> = phf_map!( "foo" => 10, "bar" => 11, ); @@ -56,11 +57,11 @@ mod map { #[test] fn test_values() { - static MAP: phf::Map<&'static str, int> = phf_map!( + static MAP: phf::Map<&'static str, isize> = phf_map!( "foo" => 10, "bar" => 11, ); - let hash = MAP.values().map(|&e| e).collect::>(); + let hash = MAP.values().map(|&e| e).collect::>(); assert!(hash.contains(&10)); assert!(hash.contains(&11)); assert_eq!(2, hash.len()); @@ -68,7 +69,7 @@ mod map { #[test] fn test_large() { - static MAP: phf::Map<&'static str, int> = phf_map!( + static MAP: phf::Map<&'static str, isize> = phf_map!( "a" => 0, "b" => 1, "c" => 2, @@ -101,7 +102,7 @@ mod map { #[test] fn test_macro_key() { - static MAP: phf::Map<&'static str, int> = phf_map!( + static MAP: phf::Map<&'static str, isize> = phf_map!( concat!("foo", "bar") => 1 ); assert!(Some(&1) == MAP.get(&("foobar"))); @@ -109,15 +110,15 @@ mod map { #[test] fn test_non_static_str_key() { - static MAP: phf::Map<&'static str, int> = phf_map!( + static MAP: phf::Map<&'static str, isize> = phf_map!( "a" => 0, ); - assert_eq!(Some(&0), MAP.get("a".to_string()[])); + assert_eq!(Some(&0), MAP.get(&*"a".to_string())); } #[test] fn test_index_ok() { - static MAP: phf::Map<&'static str, int> = phf_map!( + static MAP: phf::Map<&'static str, isize> = phf_map!( "a" => 0, ); assert_eq!(0, MAP["a"]); @@ -126,7 +127,7 @@ mod map { #[test] #[should_fail] fn test_index_fail() { - static MAP: phf::Map<&'static str, int> = phf_map!( + static MAP: phf::Map<&'static str, isize> = phf_map!( "a" => 0, ); MAP["b"]; @@ -134,7 +135,7 @@ mod map { macro_rules! test_key_type( ($t:ty, $($k:expr => $v:expr),+) => ({ - static MAP: phf::Map<$t, int> = phf_map! { + static MAP: phf::Map<$t, isize> = phf_map! { $($k => $v),+ }; $( @@ -153,7 +154,7 @@ mod map { #[test] fn test_array_keys() { - static MAP: phf::Map<[u8; 2], int> = phf_map!( + static MAP: phf::Map<[u8; 2], isize> = phf_map!( [0u8, 1] => 0, [2, 3u8] => 1, [4, 5] => 2, @@ -266,7 +267,7 @@ mod set { "hello", "world", }; - assert!(SET.contains("hello".to_string()[])); + assert!(SET.contains(&*"hello".to_string())); } } @@ -276,18 +277,18 @@ mod ordered_map { use phf; #[allow(dead_code)] - static TRAILING_COMMA: phf::OrderedMap<&'static str, int> = phf_ordered_map!( + static TRAILING_COMMA: phf::OrderedMap<&'static str, isize> = phf_ordered_map!( "foo" => 10, ); #[allow(dead_code)] - static NO_TRAILING_COMMA: phf::OrderedMap<&'static str, int> = phf_ordered_map!( + static NO_TRAILING_COMMA: phf::OrderedMap<&'static str, isize> = phf_ordered_map!( "foo" => 10 ); #[test] fn test_two() { - static MAP: phf::OrderedMap<&'static str, int> = phf_ordered_map!( + static MAP: phf::OrderedMap<&'static str, isize> = phf_ordered_map!( "foo" => 10, "bar" => 11, ); @@ -299,7 +300,7 @@ mod ordered_map { #[test] fn test_get_index() { - static MAP: phf::OrderedMap<&'static str, int> = phf_ordered_map!( + static MAP: phf::OrderedMap<&'static str, isize> = phf_ordered_map!( "foo" => 5, "bar" => 5, "baz" => 5, @@ -309,25 +310,25 @@ mod ordered_map { assert_eq!(None, MAP.get_index(&"xyz")); assert_eq!(&"baz", MAP.keys().idx(MAP.get_index(&"baz").unwrap()).unwrap()); - assert_eq!(Some(0), MAP.get_index("foo".to_string()[])); - assert_eq!(Some(2), MAP.get_index("baz".to_string()[])); - assert_eq!(None, MAP.get_index("xyz".to_string()[])); + assert_eq!(Some(0), MAP.get_index(&*"foo".to_string())); + assert_eq!(Some(2), MAP.get_index(&*"baz".to_string())); + assert_eq!(None, MAP.get_index(&*"xyz".to_string())); } #[test] fn test_entries() { - static MAP: phf::OrderedMap<&'static str, int> = phf_ordered_map!( + static MAP: phf::OrderedMap<&'static str, isize> = phf_ordered_map!( "foo" => 10, "bar" => 11, "baz" => 12, ); let vec = MAP.entries().map(|(&k, &v)| (k, v)).collect::>(); - assert_eq!(vec, vec!(("foo", 10i), ("bar", 11), ("baz", 12))); + assert_eq!(vec, vec!(("foo", 10is), ("bar", 11), ("baz", 12))); } #[test] fn test_keys() { - static MAP: phf::OrderedMap<&'static str, int> = phf_ordered_map!( + static MAP: phf::OrderedMap<&'static str, isize> = phf_ordered_map!( "foo" => 10, "bar" => 11, "baz" => 12, @@ -338,18 +339,18 @@ mod ordered_map { #[test] fn test_values() { - static MAP: phf::OrderedMap<&'static str, int> = phf_ordered_map!( + static MAP: phf::OrderedMap<&'static str, isize> = phf_ordered_map!( "foo" => 10, "bar" => 11, "baz" => 12, ); let vec = MAP.values().map(|&v| v).collect::>(); - assert_eq!(vec, vec!(10i, 11, 12)); + assert_eq!(vec, vec!(10is, 11, 12)); } #[test] fn test_index_ok() { - static MAP: phf::OrderedMap<&'static str, int> = phf_ordered_map!( + static MAP: phf::OrderedMap<&'static str, isize> = phf_ordered_map!( "a" => 0, ); assert_eq!(0, MAP["a"]); @@ -358,7 +359,7 @@ mod ordered_map { #[test] #[should_fail] fn test_index_fail() { - static MAP: phf::OrderedMap<&'static str, int> = phf_ordered_map!( + static MAP: phf::OrderedMap<&'static str, isize> = phf_ordered_map!( "a" => 0, ); MAP["b"]; @@ -366,10 +367,10 @@ mod ordered_map { #[test] fn test_non_static_str_key() { - static MAP: phf::OrderedMap<&'static str, int> = phf_ordered_map!( + static MAP: phf::OrderedMap<&'static str, isize> = phf_ordered_map!( "a" => 0, ); - assert_eq!(Some(&0), MAP.get("a".to_string()[])); + assert_eq!(Some(&0), MAP.get(&*"a".to_string())); } } @@ -413,9 +414,9 @@ mod ordered_set { assert_eq!(None, SET.get_index(&"xyz")); assert_eq!(&"baz", SET.iter().idx(SET.get_index(&"baz").unwrap()).unwrap()); - assert_eq!(Some(0), SET.get_index("foo".to_string()[])); - assert_eq!(Some(2), SET.get_index("baz".to_string()[])); - assert_eq!(None, SET.get_index("xyz".to_string()[])); + assert_eq!(Some(0), SET.get_index(&*"foo".to_string())); + assert_eq!(Some(2), SET.get_index(&*"baz".to_string())); + assert_eq!(None, SET.get_index(&*"xyz".to_string())); } #[test] @@ -435,6 +436,6 @@ mod ordered_set { "hello", "world", }; - assert!(SET.contains("hello".to_string()[])); + assert!(SET.contains(&*"hello".to_string())); } } diff --git a/phf_mac/src/lib.rs b/phf_mac/src/lib.rs index a60ec3da..570979ff 100644 --- a/phf_mac/src/lib.rs +++ b/phf_mac/src/lib.rs @@ -3,7 +3,7 @@ //! See the documentation for the `phf` crate for more details. #![doc(html_root_url="http://sfackler.github.io/doc")] #![feature(plugin_registrar, quote, old_orphan_check)] -#![allow(unknown_features)] +#![allow(unknown_features, unstable)] extern crate rand; extern crate syntax; @@ -225,7 +225,7 @@ fn has_duplicates(cx: &mut ExtCtxt, sp: Span, entries: &[Entry]) -> bool { let mut dups = false; let mut strings = HashMap::new(); for entry in entries.iter() { - let &(ref mut spans, _) = match strings.entry(&entry.key_contents) { + let &mut (ref mut spans, _) = match strings.entry(&entry.key_contents) { Occupied(e) => e.into_mut(), Vacant(e) => e.insert((vec![], &entry.key)), }; diff --git a/phf_mac/src/util.rs b/phf_mac/src/util.rs index 06262fe0..1fcd18b9 100644 --- a/phf_mac/src/util.rs +++ b/phf_mac/src/util.rs @@ -1,6 +1,6 @@ use std::os; use std::rc::Rc; -use std::hash::{self, Hash}; +use std::hash::{self, Hash, Hasher}; use std::iter::repeat; use syntax::ast::Expr; @@ -13,7 +13,7 @@ use rand::{Rng, SeedableRng, XorShiftRng}; use phf_shared::{self, PhfHash}; -const DEFAULT_LAMBDA: uint = 5; +const DEFAULT_LAMBDA: usize = 5; const FIXED_SEED: [u32; 4] = [3141592653, 589793238, 462643383, 2795028841]; @@ -33,7 +33,7 @@ pub enum Key { Bool(bool), } -impl Hash for Key where S: hash::Writer { +impl Hash for Key where S: Hasher + hash::Writer { fn hash(&self, state: &mut S) { match *self { Key::Str(ref s) => s.get().hash(state), @@ -80,7 +80,7 @@ pub struct Entry { pub struct HashState { key: u64, disps: Vec<(u32, u32)>, - map: Vec, + map: Vec, } pub fn generate_hash(cx: &mut ExtCtxt, sp: Span, entries: &[Entry]) -> HashState { @@ -111,8 +111,8 @@ pub fn generate_hash(cx: &mut ExtCtxt, sp: Span, entries: &[Entry]) -> HashState pub fn try_generate_hash(entries: &[Entry], rng: &mut XorShiftRng) -> Option { struct Bucket { - idx: uint, - keys: Vec, + idx: usize, + keys: Vec, } struct Hashes { @@ -138,7 +138,7 @@ pub fn try_generate_hash(entries: &[Entry], rng: &mut XorShiftRng) -> Option>(); for (i, hash) in hashes.iter().enumerate() { - buckets[(hash.g % (buckets_len as u32)) as uint].keys.push(i); + buckets[(hash.g % (buckets_len as u32)) as usize].keys.push(i); } // Sort descending @@ -171,7 +171,7 @@ pub fn try_generate_hash(entries: &[Entry], rng: &mut XorShiftRng) -> Option u32 { @@ -13,7 +13,7 @@ pub fn displace(f1: u32, f2: u32, d1: u32, d2: u32) -> u32 { #[inline] fn split(hash: u64) -> (u32, u32, u32) { - const BITS: uint = 21; + const BITS: u32 = 21; const MASK: u64 = (1 << BITS) - 1; ((hash & MASK) as u32, @@ -51,7 +51,7 @@ impl PhfHash for str { impl PhfHash for [u8] { #[inline] fn phf_hash(&self, seed: u64) -> (u32, u32, u32) { - let mut state = SipState::new_with_keys(seed, 0); + let mut state = SipHasher::new_with_keys(seed, 0); state.write(self); split(state.result()) } @@ -63,7 +63,9 @@ macro_rules! sip_impl( impl PhfHash for $t { #[inline] fn phf_hash(&self, seed: u64) -> (u32, u32, u32) { - split(sip::hash_with_keys(seed, 0, self)) + let mut hasher = SipHasher::new_with_keys(seed, 0); + self.hash(&mut hasher); + split(hasher.finish()) } } ) @@ -85,7 +87,9 @@ macro_rules! array_impl( impl PhfHash for [$t; $n] { #[inline] fn phf_hash(&self, seed: u64) -> (u32, u32, u32) { - split(sip::hash_with_keys(seed, 0, self.as_slice())) + let mut hasher = SipHasher::new_with_keys(seed, 0); + hasher.write(self.as_slice()); + split(hasher.finish()) } } )