From 13b93899b5679d425fdfff7695003bc52d4c8f0b Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 17 Aug 2014 14:08:39 -0700 Subject: [PATCH] Switch to where clause syntax --- phf/src/lib.rs | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/phf/src/lib.rs b/phf/src/lib.rs index 13e8133c..31e2a2d3 100644 --- a/phf/src/lib.rs +++ b/phf/src/lib.rs @@ -59,7 +59,7 @@ impl Collection for PhfMap { } } -impl<'a, K: PhfHash+Eq, V> Map for PhfMap { +impl<'a, K, V> Map for PhfMap where K: PhfHash+Eq { fn find(&self, key: &K) -> Option<&V> { self.get_entry(key, |k| key == k).map(|e| { let &(_, ref v) = e; @@ -68,7 +68,7 @@ impl<'a, K: PhfHash+Eq, V> Map for PhfMap { } } -impl fmt::Show for PhfMap { +impl fmt::Show for PhfMap where K: fmt::Show, V: fmt::Show { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "{{")); let mut first = true; @@ -83,13 +83,13 @@ impl fmt::Show for PhfMap { } } -impl Index for PhfMap { +impl Index for PhfMap where K: PhfHash+Eq { fn index(&self, k: &K) -> &V { self.find(k).expect("invalid key") } } -impl PhfMap { +impl PhfMap where K: PhfHash+Eq { /// Returns a reference to the map's internal static instance of the given /// key. /// @@ -117,7 +117,7 @@ impl PhfMap { } /// Like `find`, but can operate on any type that is equivalent to a key. - pub fn find_equiv>(&self, key: &T) -> Option<&V> { + pub fn find_equiv(&self, key: &T) -> Option<&V> where T: PhfHash+Equiv { self.get_entry(key, |k| key.equiv(k)).map(|e| { let &(_, ref v) = e; v @@ -126,7 +126,7 @@ impl PhfMap { /// Like `find_key`, but can operate on any type that is equivalent to a /// key. - pub fn find_key_equiv>(&self, key: &T) -> Option<&K> { + pub fn find_key_equiv(&self, key: &T) -> Option<&K> where T: PhfHash+Equiv { self.get_entry(key, |k| key.equiv(k)).map(|e| { let &(ref k, _) = e; k @@ -256,7 +256,7 @@ pub struct PhfSet { pub map: PhfMap } -impl fmt::Show for PhfSet { +impl fmt::Show for PhfSet where T: fmt::Show { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "{{")); let mut first = true; @@ -278,7 +278,7 @@ impl Collection for PhfSet { } } -impl<'a, T: PhfHash+Eq> Set for PhfSet { +impl<'a, T> Set for PhfSet where T: PhfHash+Eq { #[inline] fn contains(&self, value: &T) -> bool { self.map.contains_key(value) @@ -295,7 +295,7 @@ impl<'a, T: PhfHash+Eq> Set for PhfSet { } } -impl PhfSet { +impl PhfSet where T: PhfHash+Eq { /// Returns a reference to the set's internal static instance of the given /// key. /// @@ -310,14 +310,14 @@ impl PhfSet { /// Like `contains`, but can operate on any type that is equivalent to a /// value #[inline] - pub fn contains_equiv>(&self, key: &U) -> bool { + pub fn contains_equiv(&self, key: &U) -> bool where U: PhfHash+Equiv { self.map.find_equiv(key).is_some() } /// Like `find_key`, but can operate on any type that is equivalent to a /// value #[inline] - pub fn find_key_equiv>(&self, key: &U) -> Option<&T> { + pub fn find_key_equiv(&self, key: &U) -> Option<&T> where U: PhfHash+Equiv { self.map.find_key_equiv(key) } } @@ -394,7 +394,7 @@ pub struct PhfOrderedMap { pub entries: &'static [(K, V)], } -impl fmt::Show for PhfOrderedMap { +impl fmt::Show for PhfOrderedMap where K: fmt::Show, V: fmt::Show { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "{{")); let mut first = true; @@ -415,7 +415,7 @@ impl Collection for PhfOrderedMap { } } -impl Map for PhfOrderedMap { +impl Map for PhfOrderedMap where K: PhfHash+Eq { fn find(&self, key: &K) -> Option<&V> { self.find_entry(key, |k| k == key).map(|e| { let &(_, ref v) = e; @@ -424,13 +424,13 @@ impl Map for PhfOrderedMap { } } -impl Index for PhfOrderedMap { +impl Index for PhfOrderedMap where K: PhfHash+Eq { fn index(&self, k: &K) -> &V { self.find(k).expect("invalid key") } } -impl PhfOrderedMap { +impl PhfOrderedMap where K: PhfHash+Eq { /// Returns a reference to the map's internal static instance of the given /// key. /// @@ -444,7 +444,7 @@ impl PhfOrderedMap { } impl PhfOrderedMap { - fn find_entry(&self, key: &T, check: |&K| -> bool) -> Option<&(K, V)> { + fn find_entry(&self, key: &T, check: |&K| -> bool) -> Option<&(K, V)> where T: PhfHash { 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[(shared::displace(f1, f2, d1, d2) % (self.idxs.len() as u32)) as uint]; @@ -459,7 +459,7 @@ impl PhfOrderedMap { } /// Like `find`, but can operate on any type that is equivalent to a key. - pub fn find_equiv>(&self, key: &T) -> Option<&V> { + pub fn find_equiv(&self, key: &T) -> Option<&V> where T: PhfHash+Equiv { self.find_entry(key, |k| key.equiv(k)).map(|e| { let &(_, ref v) = e; v @@ -468,7 +468,7 @@ impl PhfOrderedMap { /// Like `find_key`, but can operate on any type that is equivalent to a /// key. - pub fn find_key_equiv>(&self, key: &T) -> Option<&K> { + pub fn find_key_equiv(&self, key: &T) -> Option<&K> where T: PhfHash+Equiv { self.find_entry(key, |k| key.equiv(k)).map(|e| { let &(ref k, _) = e; k @@ -633,7 +633,7 @@ pub struct PhfOrderedSet { pub map: PhfOrderedMap, } -impl fmt::Show for PhfOrderedSet { +impl fmt::Show for PhfOrderedSet where T: fmt::Show { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "{{")); let mut first = true; @@ -655,7 +655,7 @@ impl Collection for PhfOrderedSet { } } -impl Set for PhfOrderedSet { +impl Set for PhfOrderedSet where T: PhfHash+Eq { #[inline] fn contains(&self, value: &T) -> bool { self.map.contains_key(value) @@ -687,14 +687,14 @@ impl PhfOrderedSet { /// Like `contains`, but can operate on any type that is equivalent to a /// value #[inline] - pub fn contains_equiv>(&self, key: &U) -> bool { + pub fn contains_equiv(&self, key: &U) -> bool where U: PhfHash+Equiv { self.map.find_equiv(key).is_some() } /// Like `find_key`, but can operate on any type that is equivalent to a /// value #[inline] - pub fn find_key_equiv>(&self, key: &U) -> Option<&T> { + pub fn find_key_equiv(&self, key: &U) -> Option<&T> where U: PhfHash+Equiv { self.map.find_key_equiv(key) }