From 88abf6c8b081439c8cb1458289790d0ee8f4d04a Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 15 Nov 2014 08:50:20 -0800 Subject: [PATCH] Switch from find to get --- phf/src/map.rs | 16 ++++++------ phf/src/ordered_map.rs | 36 +++++++++++++-------------- phf/src/ordered_set.rs | 22 ++++++++--------- phf/src/set.rs | 12 ++++----- phf/tests/test.rs | 56 +++++++++++++++++++++--------------------- 5 files changed, 71 insertions(+), 71 deletions(-) diff --git a/phf/src/map.rs b/phf/src/map.rs index 00447747..cc218f71 100644 --- a/phf/src/map.rs +++ b/phf/src/map.rs @@ -55,26 +55,26 @@ impl fmt::Show for Map where K: fmt::Show, V: fmt::Show { impl Index for Map where K: PhfHash+Eq { fn index(&self, k: &K) -> &V { - self.find(k).expect("invalid key") + self.get(k).expect("invalid key") } } impl Map where K: PhfHash+Eq { /// Returns a reference to the value that `key` maps to. - pub fn find(&self, key: &K) -> Option<&V> { + pub fn get(&self, key: &K) -> Option<&V> { self.get_entry(key, |k| key == k).map(|e| &e.1) } /// Determines if `key` is in the `Map`. pub fn contains_key(&self, key: &K) -> bool { - self.find(key).is_some() + self.get(key).is_some() } /// Returns a reference to the map's internal static instance of the given /// key. /// /// This can be useful for interning schemes. - pub fn find_key(&self, key: &K) -> Option<&K> { + pub fn get_key(&self, key: &K) -> Option<&K> { self.get_entry(key, |k| key == k).map(|e| &e.0) } } @@ -102,14 +102,14 @@ impl Map { } } - /// Like `find`, but can operate on any type that is equivalent to a key. - pub fn find_equiv(&self, key: &T) -> Option<&V> where T: PhfHash+Equiv { + /// Like `get`, but can operate on any type that is equivalent to a key. + pub fn get_equiv(&self, key: &T) -> Option<&V> where T: PhfHash+Equiv { self.get_entry(key, |k| key.equiv(k)).map(|e| &e.1) } - /// Like `find_key`, but can operate on any type that is equivalent to a + /// Like `get_key`, but can operate on any type that is equivalent to a /// key. - pub fn find_key_equiv(&self, key: &T) -> Option<&K> where T: PhfHash+Equiv { + pub fn get_key_equiv(&self, key: &T) -> Option<&K> where T: PhfHash+Equiv { self.get_entry(key, |k| key.equiv(k)).map(|e| &e.0) } diff --git a/phf/src/ordered_map.rs b/phf/src/ordered_map.rs index acfec983..b2ccd369 100644 --- a/phf/src/ordered_map.rs +++ b/phf/src/ordered_map.rs @@ -60,33 +60,33 @@ impl fmt::Show for OrderedMap where K: fmt::Show, V: fmt::Show { impl Index for OrderedMap where K: PhfHash+Eq { fn index(&self, k: &K) -> &V { - self.find(k).expect("invalid key") + self.get(k).expect("invalid key") } } impl OrderedMap where K: PhfHash+Eq { /// Returns a reference to the value that `key` maps to. - pub fn find(&self, key: &K) -> Option<&V> { - self.find_entry(key, |k| key == k).map(|(_, e)| &e.1) + pub fn get(&self, key: &K) -> Option<&V> { + self.get_entry(key, |k| key == k).map(|(_, e)| &e.1) } /// Determines if `key` is in the `Map`. pub fn contains_key(&self, key: &K) -> bool { - self.find(key).is_some() + self.get(key).is_some() } /// Returns a reference to the map's internal static instance of the given /// key. /// /// This can be useful for interning schemes. - pub fn find_key(&self, key: &K) -> Option<&K> { - self.find_entry(key, |k| k == key).map(|(_, e)| &e.0) + pub fn get_key(&self, key: &K) -> Option<&K> { + self.get_entry(key, |k| k == key).map(|(_, e)| &e.0) } /// Returns the index of the key within the list used to initialize /// the ordered map. - pub fn find_index(&self, key: &K) -> Option { - self.find_entry(key, |k| k == key).map(|(i, _)| i) + pub fn get_index(&self, key: &K) -> Option { + self.get_entry(key, |k| k == key).map(|(i, _)| i) } } @@ -101,7 +101,7 @@ impl OrderedMap { self.entries.len() } - fn find_entry(&self, key: &T, check: |&K| -> bool) -> Option<(uint, &(K, V))> + fn get_entry(&self, key: &T, check: |&K| -> bool) -> Option<(uint, &(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]; @@ -115,21 +115,21 @@ impl OrderedMap { } } - /// Like `find`, but can operate on any type that is equivalent to a key. - pub fn find_equiv(&self, key: &T) -> Option<&V> where T: PhfHash+Equiv { - self.find_entry(key, |k| key.equiv(k)).map(|(_, e)| &e.1) + /// Like `get`, but can operate on any type that is equivalent to a key. + pub fn get_equiv(&self, key: &T) -> Option<&V> where T: PhfHash+Equiv { + self.get_entry(key, |k| key.equiv(k)).map(|(_, e)| &e.1) } - /// Like `find_key`, but can operate on any type that is equivalent to a + /// Like `get_key`, but can operate on any type that is equivalent to a /// key. - pub fn find_key_equiv(&self, key: &T) -> Option<&K> where T: PhfHash+Equiv { - self.find_entry(key, |k| key.equiv(k)).map(|(_, e)| &e.0) + pub fn get_key_equiv(&self, key: &T) -> Option<&K> where T: PhfHash+Equiv { + self.get_entry(key, |k| key.equiv(k)).map(|(_, e)| &e.0) } - /// Like `find_index`, but can operate on any type that is equivalent to a + /// Like `get_index`, but can operate on any type that is equivalent to a /// key. - pub fn find_index_equiv(&self, key: &T) -> Option where T: PhfHash+Equiv { - self.find_entry(key, |k| key.equiv(k)).map(|(i, _)| i) + pub fn get_index_equiv(&self, key: &T) -> Option where T: PhfHash+Equiv { + self.get_entry(key, |k| key.equiv(k)).map(|(i, _)| i) } /// Returns an iterator over the key/value pairs in the map. diff --git a/phf/src/ordered_set.rs b/phf/src/ordered_set.rs index 658d888a..d271360a 100644 --- a/phf/src/ordered_set.rs +++ b/phf/src/ordered_set.rs @@ -56,14 +56,14 @@ impl OrderedSet { /// /// This can be useful for interning schemes. #[inline] - pub fn find_key(&self, key: &T) -> Option<&T> { - self.map.find_key(key) + pub fn get_key(&self, key: &T) -> Option<&T> { + self.map.get_key(key) } /// Returns the index of the key within the list used to initialize /// the ordered set. - pub fn find_index(&self, key: &T) -> Option { - self.map.find_index(key) + pub fn get_index(&self, key: &T) -> Option { + self.map.get_index(key) } /// Returns true if `value` is in the `Set`. @@ -108,20 +108,20 @@ impl OrderedSet { /// value #[inline] pub fn contains_equiv(&self, key: &U) -> bool where U: PhfHash+Equiv { - self.map.find_equiv(key).is_some() + self.map.get_equiv(key).is_some() } - /// Like `find_key`, but can operate on any type that is equivalent to a + /// Like `get_key`, but can operate on any type that is equivalent to a /// value #[inline] - pub fn find_key_equiv(&self, key: &U) -> Option<&T> where U: PhfHash+Equiv { - self.map.find_key_equiv(key) + pub fn get_key_equiv(&self, key: &U) -> Option<&T> where U: PhfHash+Equiv { + self.map.get_key_equiv(key) } - /// Like `find_index`, but can operate on any type that is equivalent to a + /// Like `get_index`, but can operate on any type that is equivalent to a /// key. - pub fn find_index_equiv(&self, key: &U) -> Option where U: PhfHash+Equiv { - self.map.find_index_equiv(key) + pub fn get_index_equiv(&self, key: &U) -> Option where U: PhfHash+Equiv { + self.map.get_index_equiv(key) } /// Returns an iterator over the values in the set. diff --git a/phf/src/set.rs b/phf/src/set.rs index 9ef8969e..45b41da9 100644 --- a/phf/src/set.rs +++ b/phf/src/set.rs @@ -54,8 +54,8 @@ impl Set where T: PhfHash+Eq { /// /// This can be useful for interning schemes. #[inline] - pub fn find_key(&self, key: &T) -> Option<&T> { - self.map.find_key(key) + pub fn get_key(&self, key: &T) -> Option<&T> { + self.map.get_key(key) } /// Returns true if `value` is in the `Set`. @@ -100,14 +100,14 @@ impl Set { /// value #[inline] pub fn contains_equiv(&self, key: &U) -> bool where U: PhfHash+Equiv { - self.map.find_equiv(key).is_some() + self.map.get_equiv(key).is_some() } - /// Like `find_key`, but can operate on any type that is equivalent to a + /// Like `get_key`, but can operate on any type that is equivalent to a /// value #[inline] - pub fn find_key_equiv(&self, key: &U) -> Option<&T> where U: PhfHash+Equiv { - self.map.find_key_equiv(key) + pub fn get_key_equiv(&self, key: &U) -> Option<&T> where U: PhfHash+Equiv { + self.map.get_key_equiv(key) } } diff --git a/phf/tests/test.rs b/phf/tests/test.rs index 78e4ffaf..ec2edbfd 100644 --- a/phf/tests/test.rs +++ b/phf/tests/test.rs @@ -24,9 +24,9 @@ mod map { "foo" => 10, "bar" => 11, ); - assert!(Some(&10) == MAP.find(&("foo"))); - assert!(Some(&11) == MAP.find(&("bar"))); - assert_eq!(None, MAP.find(&("asdf"))); + assert!(Some(&10) == MAP.get(&("foo"))); + assert!(Some(&11) == MAP.get(&("bar"))); + assert_eq!(None, MAP.get(&("asdf"))); assert_eq!(2, MAP.len()); } @@ -96,7 +96,7 @@ mod map { "y" => 24, "z" => 25, ); - assert!(MAP.find(&("a")) == Some(&0)); + assert!(MAP.get(&("a")) == Some(&0)); } #[test] @@ -104,7 +104,7 @@ mod map { static MAP: phf::Map<&'static str, int> = phf_map!( concat!("foo", "bar") => 1 ); - assert!(Some(&1) == MAP.find(&("foobar"))); + assert!(Some(&1) == MAP.get(&("foobar"))); } #[test] @@ -112,7 +112,7 @@ mod map { static MAP: phf::Map<&'static str, int> = phf_map!( "a" => 0, ); - assert_eq!(Some(&0), MAP.find_equiv("a".to_string()[])); + assert_eq!(Some(&0), MAP.get_equiv("a".to_string()[])); } #[test] @@ -138,7 +138,7 @@ mod map { $($k => $v),+ }; $( - assert_eq!(Some(&$v), MAP.find(&$k)); + assert_eq!(Some(&$v), MAP.get(&$k)); )+ }) ) @@ -271,27 +271,27 @@ mod ordered_map { "foo" => 10, "bar" => 11, ); - assert!(Some(&10) == MAP.find(&"foo")); - assert!(Some(&11) == MAP.find(&"bar")); - assert_eq!(None, MAP.find(&"asdf")); + assert!(Some(&10) == MAP.get(&"foo")); + assert!(Some(&11) == MAP.get(&"bar")); + assert_eq!(None, MAP.get(&"asdf")); assert_eq!(2, MAP.len()); } #[test] - fn test_find_index() { + fn test_get_index() { static MAP: phf::OrderedMap<&'static str, int> = phf_ordered_map!( "foo" => 5, "bar" => 5, "baz" => 5, ); - assert_eq!(Some(0), MAP.find_index(&"foo")); - assert_eq!(Some(2), MAP.find_index(&"baz")); - assert_eq!(None, MAP.find_index(&"xyz")); - assert_eq!(&"baz", MAP.keys().idx(MAP.find_index(&"baz").unwrap()).unwrap()); + assert_eq!(Some(0), MAP.get_index(&"foo")); + assert_eq!(Some(2), MAP.get_index(&"baz")); + assert_eq!(None, MAP.get_index(&"xyz")); + assert_eq!(&"baz", MAP.keys().idx(MAP.get_index(&"baz").unwrap()).unwrap()); - assert_eq!(Some(0), MAP.find_index_equiv("foo".to_string()[])); - assert_eq!(Some(2), MAP.find_index_equiv("baz".to_string()[])); - assert_eq!(None, MAP.find_index_equiv("xyz".to_string()[])); + assert_eq!(Some(0), MAP.get_index_equiv("foo".to_string()[])); + assert_eq!(Some(2), MAP.get_index_equiv("baz".to_string()[])); + assert_eq!(None, MAP.get_index_equiv("xyz".to_string()[])); } #[test] @@ -349,7 +349,7 @@ mod ordered_map { static MAP: phf::OrderedMap<&'static str, int> = phf_ordered_map!( "a" => 0, ); - assert_eq!(Some(&0), MAP.find_equiv("a".to_string()[])); + assert_eq!(Some(&0), MAP.get_equiv("a".to_string()[])); } } @@ -381,20 +381,20 @@ mod ordered_set { } #[test] - fn test_find_index() { + fn test_get_index() { static SET: phf::OrderedSet<&'static str> = phf_ordered_set! { "foo", "bar", "baz", }; - assert_eq!(Some(0), SET.find_index(&"foo")); - assert_eq!(Some(2), SET.find_index(&"baz")); - assert_eq!(None, SET.find_index(&"xyz")); - assert_eq!(&"baz", SET.iter().idx(SET.find_index(&"baz").unwrap()).unwrap()); - - assert_eq!(Some(0), SET.find_index_equiv("foo".to_string()[])); - assert_eq!(Some(2), SET.find_index_equiv("baz".to_string()[])); - assert_eq!(None, SET.find_index_equiv("xyz".to_string()[])); + assert_eq!(Some(0), SET.get_index(&"foo")); + assert_eq!(Some(2), SET.get_index(&"baz")); + 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_equiv("foo".to_string()[])); + assert_eq!(Some(2), SET.get_index_equiv("baz".to_string()[])); + assert_eq!(None, SET.get_index_equiv("xyz".to_string()[])); } #[test]